Class: Elastic::Core::DefaultMiddleware

Inherits:
BaseMiddleware show all
Defined in:
lib/elastic/core/default_middleware.rb

Instance Attribute Summary

Attributes inherited from BaseMiddleware

#target

Instance Method Summary collapse

Methods inherited from BaseMiddleware

#initialize

Constructor Details

This class inherits a constructor from Elastic::Core::BaseMiddleware

Instance Method Details

#build_from_data(_data, _options) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/elastic/core/default_middleware.rb', line 36

def build_from_data(_data, _options)
  case target_mode
  when :custom_build
    target.build_from_elastic_data(_data)
  when :open_struct
    OpenStruct.new _data
  end
end

#collect_all(_options, &_block) ⇒ Object



16
17
18
19
# File 'lib/elastic/core/default_middleware.rb', line 16

def collect_all(_options, &_block)
  method = collect_method_for(target)
  target.public_send(method, &_block) if method
end

#collect_from(_collection, _options, &_block) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
# File 'lib/elastic/core/default_middleware.rb', line 21

def collect_from(_collection, _options, &_block)
  method = collect_method_for(_collection)
  raise ArgumentError, "Could not find a method to iterate over collection" if method.nil?
  _collection.public_send(method, &_block)
end

#field_options_for(_field, _options) ⇒ Object



12
13
14
# File 'lib/elastic/core/default_middleware.rb', line 12

def field_options_for(_field, _options)
  nil
end

#find_by_ids(_ids, _options) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/elastic/core/default_middleware.rb', line 27

def find_by_ids(_ids, _options)
  case target_mode
  when :find_multiple_ids
    target.find_by_elastic_ids(_ids)
  when :find_single_id
    _ids.map { |id| target.find_by_elastic_id(id) }
  end
end

#modeObject



3
4
5
6
7
8
9
10
# File 'lib/elastic/core/default_middleware.rb', line 3

def mode
  case target_mode
  when :find_multiple_ids, :find_single_id
    :index
  else
    :storage
  end
end