Sha256: fee11d1e28699e08cb975863f855bb26ddb39649d0b632e30ef1b6f8a4104947

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'active_support/concern'

module Georgia
  module Indexer
    autoload :SolrAdapter, 'georgia/indexer/solr_adapter'
    autoload :TireAdapter, 'georgia/indexer/tire_adapter'

    def self.adapter
      @@adapter ||= adapter_lookup
    end

    # Delegates search to the adapter
    def self.search model, params
      adapter.search model, params
    end

    private

    def self.adapter_lookup
      @adapter_lookup ||= (case Georgia.indexer
        when :solr then SolrAdapter
        when :tire then TireAdapter
        else
          TireAdapter
        end)
    end

    module Adapter

      class << self
        def included(klass)
          extension = Extension.new(klass)
          begin
            require extension.path
            klass.send(:include, extension.name)
          rescue => ex
            raise "No extension for the #{Georgia.indexer} indexer: #{ex.message}"
          end
        end

        class Extension
          def initialize klass
            @klass = klass
          end

          def name
            name = @klass.to_s.gsub('::', '') + 'Extension'
            "#{Georgia::Indexer.adapter}::#{name}".constantize
          end

          def path
            "georgia/indexer/extensions/#{Georgia.indexer}_adapter/#{filename}"
          end

          def filename
            @klass.to_s.underscore
          end
        end
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
georgia-0.7.6 lib/georgia/indexer.rb