class Elastic::Railties::ARMiddleware

Public Class Methods

accepts?(_target) click to toggle source
# File lib/elastic/railties/ar_middleware.rb, line 3
def self.accepts?(_target)
  _target < ::ActiveRecord::Base
end

Public Instance Methods

collect_all(_options, &_block) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
mode() click to toggle source
# File lib/elastic/railties/ar_middleware.rb, line 7
def mode
  :index # storage mode not supported for AR
end

Private Instance Methods

order_results(_ordered_ids, _results) click to toggle source
# File lib/elastic/railties/ar_middleware.rb, line 40
def order_results(_ordered_ids, _results)
  hash = _results.each_with_object({}) { |o, h| h[o.id] = o }
  _ordered_ids.map { |id| hash[id.to_i] }
end