Class: Chewy::Type::Adapter::Object
- Defined in:
- lib/chewy/type/adapter/object.rb
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
-
#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 = args. @target = args.first end |
Instance Method Details
#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 methods delete_from_index? or destroyed? are defined for object and any return true 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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chewy/type/adapter/object.rb', line 31 def import *args, &block = args. batch_size = .delete(:batch_size) || BATCH_SIZE objects = args.flatten.compact objects.each_slice(batch_size).map do |group| action_groups = group.group_by do |object| raise "Object is not a `#{target}`" if class_target? && !object.is_a?(target) delete = object.delete_from_index? if object.respond_to?(:delete_from_index?) delete ||= object.destroyed? if object.respond_to?(:destroyed?) delete ? :delete : :index end block.call action_groups end.all? end |
#load(*args) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/chewy/type/adapter/object.rb', line 47 def load *args = args. objects = args.flatten if class_target? 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 |