Class: Chewy::Type::Adapter::Object
- Defined in:
- lib/chewy/type/adapter/object.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #identify(collection) ⇒ Object
-
#import(*args, &block) ⇒ Object
Imports passed data with options.
-
#initialize(*args) ⇒ Object
constructor
A new instance of Object.
- #load(*args) ⇒ Object
- #name ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*args) ⇒ Object
Returns a new instance of Object.
7 8 9 10 |
# File 'lib/chewy/type/adapter/object.rb', line 7 def initialize(*args) @options = args. @target = args.first end |
Instance Method Details
#identify(collection) ⇒ Object
16 17 18 |
# File 'lib/chewy/type/adapter/object.rb', line 16 def identify(collection) Array.wrap(collection) end |
#import(*args, &block) ⇒ Object
Imports passed data with options
Import data types:
* Array ob objects
Import options:
<tt>:batch_size</tt> - import batch size, 1000 objects by default
If method ‘destroyed?` is defined for object and returns true or object satisfy `delete_if` type option then object will be deleted from index. But to be destroyed objects need to respond to `id` method as well, so ElasticSearch could know which one to delete.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/chewy/type/adapter/object.rb', line 35 def import(*args, &block) = args. [:batch_size] ||= BATCH_SIZE objects = if args.empty? && @target.respond_to?(import_all_method) @target.send(import_all_method) else args.flatten.compact end import_objects(objects, , &block) end |
#load(*args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/chewy/type/adapter/object.rb', line 48 def load(*args) args. objects = args.flatten if target.respond_to?(load_all_method) target.send(load_all_method, objects) elsif target.respond_to?(load_one_method) objects.map { |object| target.send(load_one_method, object) } elsif target.respond_to?(:wrap) ActiveSupport::Deprecation.warn('Loading with `wrap` method is deprecated. Rename it to `load_one` or pass `load_one_method: :my_load_method` option to `define_type`') objects.map { |object| target.wrap(object) } else objects end end |
#name ⇒ Object
12 13 14 |
# File 'lib/chewy/type/adapter/object.rb', line 12 def name @name ||= ([:name] || @target).to_s.camelize.demodulize end |