class Elasticsearch::Model::Adapter::Adapter

Contains an adapter for specific OxM or architecture.

Attributes

klass[R]

Public Class Methods

adapters() click to toggle source

Return the collection of registered adapters

@example Return the currently registered adapters

Elasticsearch::Model::Adapter.adapters
# => {
#  Elasticsearch::Model::Adapter::ActiveRecord => #<Proc:0x007...(lambda)>,
#  Elasticsearch::Model::Adapter::Mongoid => #<Proc:0x007... (lambda)>,
# }

@return [Hash] The collection of adapters

# File lib/elasticsearch/model/adapter.rb, line 103
def self.adapters
  @adapters ||= {}
end
new(klass) click to toggle source
# File lib/elasticsearch/model/adapter.rb, line 54
def initialize(klass)
  @klass = klass
end
register(name, condition) click to toggle source

Registers an adapter for specific condition

@param name [Module] The module containing the implemented interface @param condition [Proc] An object with a ‘call` method which is evaluated in {.adapter}

@example 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)
  }
)
# File lib/elasticsearch/model/adapter.rb, line 87
def self.register(name, condition)
  self.adapters[name] = condition
end

Public Instance Methods

adapter() click to toggle source

Returns the adapter module

@api private

# File lib/elasticsearch/model/adapter.rb, line 135
def adapter
  @adapter ||= begin
    self.class.adapters.find( lambda {[]} ) { |name, condition| condition.call(klass) }.first \
    || Elasticsearch::Model::Adapter::Default
  end
end
callbacks_mixin() click to toggle source

Return the module with {Default::Callbacks} interface implementation

@api private

# File lib/elasticsearch/model/adapter.rb, line 119
def callbacks_mixin
  adapter.const_get(:Callbacks)
end
importing_mixin() click to toggle source

Return the module with {Default::Importing} interface implementation

@api private

# File lib/elasticsearch/model/adapter.rb, line 127
def importing_mixin
  adapter.const_get(:Importing)
end
records_mixin() click to toggle source

Return the module with {Default::Records} interface implementation

@api private

# File lib/elasticsearch/model/adapter.rb, line 111
def records_mixin
  adapter.const_get(:Records)
end