Class: Elastic::Railties::ARMiddleware

Inherits:
Core::BaseMiddleware show all
Defined in:
lib/elastic/railties/ar_middleware.rb

Instance Attribute Summary

Attributes inherited from Core::BaseMiddleware

#target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::BaseMiddleware

#build_from_data, #initialize

Constructor Details

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

Class Method Details

.accepts?(_target) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/elastic/railties/ar_middleware.rb', line 3

def self.accepts?(_target)
  _target < ::ActiveRecord::Base
end

Instance Method Details

#collect_all(_options, &_block) ⇒ Object



19
20
21
# File 'lib/elastic/railties/ar_middleware.rb', line 19

def collect_all(_options, &_block)
  collect_from(target, _options, &_block)
end

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



23
24
25
26
27
28
29
30
# File 'lib/elastic/railties/ar_middleware.rb', line 23

def collect_from(_collection, _options, &_block)
  ARHelpers.find_each_with_options(
    _collection,
    includes: _options[:ar_collect_includes],
    scope: _options[:ar_collect_scope],
    &_block
  )
end

#field_options_for(_field, _options) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/elastic/railties/ar_middleware.rb', line 11

def field_options_for(_field, _options)
  if Rails.version.to_f >= 4.2
    ARHelpers.infer_ar5_field_options(target, _field)
  else
    ARHelpers.infer_ar4_field_options(target, _field)
  end
end

#find_by_ids(_ids, _options) ⇒ Object



32
33
34
35
36
# File 'lib/elastic/railties/ar_middleware.rb', line 32

def find_by_ids(_ids, _options)
  results = target.where(id: _ids).order('id ASC')
  results = results.includes(_options[:ar_includes]) if _options.key? :ar_includes
  order_results _ids, results
end

#modeObject



7
8
9
# File 'lib/elastic/railties/ar_middleware.rb', line 7

def mode
  :index # storage mode not supported for AR
end