module Elastic::Railties::ARHelpers
Public Instance Methods
find_each_with_options(_collection, includes: nil, scope: nil, &_block)
click to toggle source
# File lib/elastic/railties/ar_helpers.rb, line 5 def find_each_with_options(_collection, includes: nil, scope: nil, &_block) if _collection.respond_to? :find_each _collection = _collection.includes(*includes) if includes _collection = _collection.send(scope) if scope _collection.find_each(&_block) elsif _collection.respond_to? :each ActiveRecord::Associations::Preloader.new.preload(_collection, includes) if includes _collection.each(&_block) else raise 'Elastic ActiveRecord importing is only supported for collection types' end end
infer_ar4_field_options(_klass, _field)
click to toggle source
# File lib/elastic/railties/ar_helpers.rb, line 18 def infer_ar4_field_options(_klass, _field) # TODO: consider methods occluded by an override: # AR defines methods, this wont work: return nil if _klass.method_defined? _field return nil unless _klass.serialized_attributes[_field].nil? # occluded by serializer return nil if _klass.columns_hash[_field].nil? ar_type_to_options _klass.columns_hash[_field].type end
infer_ar5_field_options(_klass, _field)
click to toggle source
# File lib/elastic/railties/ar_helpers.rb, line 27 def infer_ar5_field_options(_klass, _field) # TODO: consider methods occluded by an override: # AR defines methods, this wont work: return nil if _klass.method_defined? _field meta = _klass.type_for_attribute _field return nil if meta.to_s == 'ActiveRecord::Type::Serialized' # occluded by serializer ar_type_to_options meta.type end
Private Instance Methods
ar_type_to_options(_type)
click to toggle source
rubocop:disable Metrics/CyclomaticComplexity
# File lib/elastic/railties/ar_helpers.rb, line 39 def ar_type_to_options(_type) case _type.try(:to_sym) when :text then { type: :text } when :string then { type: :keyword } when :integer then { type: :long } # not sure.. when :float, :decimal then { type: :double } # not sure.. when :date then { type: :date } when :datetime then { type: :time } when :boolean then { type: :boolean } end end