Method: Elasticsearch::Model::Adapter::Adapter.register

Defined in:
lib/elasticsearch/model/adapter.rb

.register(name, condition) ⇒ Object

Registers an adapter for specific condition

Examples:

Register an adapter for DataMapper


module DataMapperAdapter

  # Implement the interface for fetching records
  #
  module Records
    def records
      klass.all(id: @ids)
    end

    # ...
  end
end

# Register the adapter
#
Elasticsearch::Model::Adapter.register(
  DataMapperAdapter,
  lambda { |klass|
    defined?(::DataMapper::Resource) and klass.ancestors.include?(::DataMapper::Resource)
  }
)

Parameters:

  • name (Module)

    The module containing the implemented interface

  • condition (Proc)

    An object with a ‘call` method which is evaluated in #adapter



102
103
104
# File 'lib/elasticsearch/model/adapter.rb', line 102

def self.register(name, condition)
  self.adapters[name] = condition
end