Sha256: d58d46f458afa099924dfcdd2e95987a7f63fbbcc8c8b15bdc44260a5fb76a25

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

module Chewy
  class Type
    module Adapter
      # Basic adapter class. Contains interface, need to implement to add any classes support
      class Base
        BATCH_SIZE = 1000

        # Camelcased name, used as type class constant name.
        # For returned value 'Product' will be generated class name `ProductsIndex::Product`
        #
        def name
          raise NotImplementedError
        end

        # 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`
        #
        def type_name
          @type_name ||= name.underscore
        end

        # Splits passed objects to groups according to `:batch_size` options.
        # For every group crates hash with action keys. Example:
        #
        #   { delete: [object1, object2], index: [object3, object4, object5] }
        #
        # Returns true id all the block call returns true and false otherwise
        #
        def import *args, &block
          raise NotImplementedError
        end

        # Returns array of loaded objects for passed objects array. If some object
        # was not loaded, it returns `nil` in the place of this object
        #
        #   load(double(id: 1), double(id: 2), double(id: 3)) #=>
        #     # [<Product id: 1>, nil, <Product id: 3>], assuming, #2 was not found
        #
        def load *args
          raise NotImplementedError
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chewy-0.6.2 lib/chewy/type/adapter/base.rb
chewy-0.6.1 lib/chewy/type/adapter/base.rb
chewy-0.6.0 lib/chewy/type/adapter/base.rb
chewy-0.5.2 lib/chewy/type/adapter/base.rb