Module: Elastic::Railties::ARHelpers
Instance Method Summary collapse
- #find_each_with_options(_collection, includes: nil, scope: nil, &_block) ⇒ Object
- #infer_ar4_field_options(_klass, _field) ⇒ Object
- #infer_ar5_field_options(_klass, _field) ⇒ Object
Instance Method Details
#find_each_with_options(_collection, includes: nil, scope: nil, &_block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/elastic/railties/ar_helpers.rb', line 5 def (_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) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/elastic/railties/ar_helpers.rb', line 18 def (_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? _klass.columns_hash[_field].type end |
#infer_ar5_field_options(_klass, _field) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/elastic/railties/ar_helpers.rb', line 27 def (_klass, _field) # TODO: consider methods occluded by an override: # AR defines methods, this wont work: return nil if _klass.method_defined? _field = _klass.type_for_attribute _field return nil if .to_s == 'ActiveRecord::Type::Serialized' # occluded by serializer .type end |