Class: Chewy::Index::Adapter::Base
- Inherits:
-
Object
- Object
- Chewy::Index::Adapter::Base
- Defined in:
- lib/chewy/index/adapter/base.rb
Overview
Basic adapter class. Contains interface, need to implement to add any classes support
Constant Summary collapse
- BATCH_SIZE =
1000
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
-
.accepts?(_target) ⇒ Boolean
Returns
true
if this adapter is applicable for the given target.
Instance Method Summary collapse
-
#identify(_collection) ⇒ Object
Returns shortest identifies for further postponed importing.
-
#import(_batch) {|_batch| ... } ⇒ true, false
Splits passed objects to groups according to
:batch_size
options. - #import_fields(_fields, _batch_size) {|batch| ... } ⇒ Object
-
#import_references(_batch_size) {|batch| ... } ⇒ Object
Uses the same strategy as import for the passed arguments, and returns an array of references to the passed objects.
-
#load(_ids, **_options) ⇒ Object
Returns array of loaded objects for passed ids array.
-
#name ⇒ Object
Camelcased name.
-
#type_name ⇒ Object
Underscored type name, user for elasticsearch type creation and for type class access with ProductsIndex.type_hash hash or method.
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/chewy/index/adapter/base.rb', line 8 def @options end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/chewy/index/adapter/base.rb', line 8 def target @target end |
Class Method Details
.accepts?(_target) ⇒ Boolean
Returns true
if this adapter is applicable for the given target.
12 13 14 |
# File 'lib/chewy/index/adapter/base.rb', line 12 def self.accepts?(_target) true end |
Instance Method Details
#identify(_collection) ⇒ Object
Returns shortest identifies for further postponed importing. For ORM/ODM it will be an array of ids for simple objects - just objects themselves
34 35 36 |
# File 'lib/chewy/index/adapter/base.rb', line 34 def identify(_collection) raise NotImplementedError end |
#import(_batch) {|_batch| ... } ⇒ true, false
Splits passed objects to groups according to :batch_size
options.
For every group creates hash with action keys. Example:
{ delete: [object_or_id1, object_or_id2], index: [object3, object4, object5] }
45 46 47 |
# File 'lib/chewy/index/adapter/base.rb', line 45 def import(_batch, &_block) raise NotImplementedError end |
#import_fields(_fields, _batch_size) {|batch| ... } ⇒ Object
55 56 57 |
# File 'lib/chewy/index/adapter/base.rb', line 55 def import_fields(_fields, _batch_size, &_block) raise NotImplementedError end |
#import_references(_batch_size) {|batch| ... } ⇒ Object
Uses the same strategy as import for the passed arguments, and returns an array of references to the passed objects. Returns ids if possible. Otherwise - and array of objects themselves.
65 66 67 |
# File 'lib/chewy/index/adapter/base.rb', line 65 def import_references(_batch_size, &_block) raise NotImplementedError end |
#load(_ids, **_options) ⇒ Object
Returns array of loaded objects for passed ids array. If some object
was not loaded, it returns nil
in the place of this object
load([1, 2, 3]) #=>
# [
75 76 77 |
# File 'lib/chewy/index/adapter/base.rb', line 75 def load(_ids, **) raise NotImplementedError end |
#name ⇒ Object
Camelcased name.
18 19 20 |
# File 'lib/chewy/index/adapter/base.rb', line 18 def name raise NotImplementedError end |
#type_name ⇒ Object
Underscored type name, user for elasticsearch type creation
and for type class access with ProductsIndex.type_hash hash or method.
ProductsIndex.type_hash['product']
or ProductsIndex.product
26 27 28 |
# File 'lib/chewy/index/adapter/base.rb', line 26 def type_name @type_name ||= name.underscore end |