module FirmIndexer
  class << self
    def index_firm(firm)
      if !firm.destroyed? && firm.publishable?
        store_firm(firm)
      else
        delete_firm(firm)
      end
    end

    def handle_firm_changed(firm)
      index_firm(firm)
    end

    def handle_aggregate_changed(aggregate)
      index_firm(aggregate.firm) if firm_exists?(aggregate.firm)
    end

    def store_firm(firm)
      FirmRepository.new.store(firm)
    end

    def delete_firm(firm)
      FirmRepository.new.delete(firm.id)
    end

    def firm_exists?(firm)
      return false if (firm.nil? || firm.destroyed?)
      Firm.exists?(firm.id)
    end
  end
end

module FirmIndexer
  class << self
    def index_firm(firm)
      if !firm.destroyed? && firm.publishable?
        store_firm(firm)
      else
        delete_firm(firm)
      end
    end

    def handle_firm_changed(firm)
      index_firm(firm)
    end

    def handle_aggregate_changed(aggregate)
      index_firm(aggregate.firm) if firm_exists?(aggregate.firm)
    end

    def firm_exists?(firm)
      return false if (firm.nil? || firm.destroyed?)
      Firm.exists?(firm.id)
    end

    private

    def store_firm(firm)
      FirmRepository.new.store(firm)
    end

    def delete_firm(firm)
      FirmRepository.new.delete(firm.id)
    end
  end
end

Make store_firm and delete_firm private
Make store_firm and delete_firm private
