Class: Chewy::Type::Adapter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/chewy/type/adapter/base.rb

Overview

Basic adapter class. Contains interface, need to implement to add any classes support

Direct Known Subclasses

Object, Orm

Constant Summary collapse

BATCH_SIZE =
1000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/chewy/type/adapter/base.rb', line 8

def options
  @options
end

#targetObject (readonly)

Returns the value of attribute target.



8
9
10
# File 'lib/chewy/type/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.

Returns:

  • (Boolean)


12
13
14
# File 'lib/chewy/type/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

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/chewy/type/adapter/base.rb', line 35

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] }

Yield Parameters:

Returns:

  • (true, false)

    returns true if all the block call returns true and false otherwise

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/chewy/type/adapter/base.rb', line 46

def import(_batch, &_block)
  raise NotImplementedError
end

#import_fields(_fields, _batch_size) {|batch| ... } ⇒ Object

Unlike #import fetches only ids (references) to the imported objects, using the same procedures as #import.

Parameters:

  • _fields (Array<Symbol>)

    additional fields to fetch

  • _batch_size (Integer)

    batch size, defaults to 1000

Yield Parameters:

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/chewy/type/adapter/base.rb', line 56

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.

Parameters:

  • _batch_size (Integer)

    batch size, defaults to 1000

Yield Parameters:

Raises:

  • (NotImplementedError)


66
67
68
# File 'lib/chewy/type/adapter/base.rb', line 66

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]) #=> # [, nil, ], assuming, #2 was not found

Raises:

  • (NotImplementedError)


76
77
78
# File 'lib/chewy/type/adapter/base.rb', line 76

def load(_ids, **_options)
  raise NotImplementedError
end

#nameObject

Camelcased name, used as type class constant name. For returned value 'Product' will be generated class name ProductsIndex::Product

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/chewy/type/adapter/base.rb', line 19

def name
  raise NotImplementedError
end

#type_nameObject

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



27
28
29
# File 'lib/chewy/type/adapter/base.rb', line 27

def type_name
  @type_name ||= name.underscore
end