Class: Chewy::Type::Adapter::Sequel

Inherits:
Orm show all
Defined in:
lib/chewy/type/adapter/sequel.rb

Constant Summary

Constants inherited from Base

Base::BATCH_SIZE

Instance Attribute Summary collapse

Attributes inherited from Base

#options, #target

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Orm

#import, #initialize, #load, #name

Methods inherited from Base

#import, #load, #name, #type_name

Constructor Details

This class inherits a constructor from Chewy::Type::Adapter::Orm

Instance Attribute Details

#default_scopeObject (readonly) Also known as: default_dataset

Returns the value of attribute default_scope.



7
8
9
# File 'lib/chewy/type/adapter/sequel.rb', line 7

def default_scope
  @default_scope
end

Class Method Details

.accepts?(target) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# File 'lib/chewy/type/adapter/sequel.rb', line 10

def self.accepts?(target)
  defined?(::Sequel::Model) && (
    target.is_a?(Class) && target < ::Sequel::Model ||
    target.is_a?(::Sequel::Dataset))
end

Instance Method Details

#identify(collection) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/chewy/type/adapter/sequel.rb', line 16

def identify collection
  if collection.is_a?(relation_class)
    pluck_ids(collection)
  else
    Array.wrap(collection).map do |entity|
      entity.is_a?(object_class) ? entity.public_send(primary_key) : entity
    end
  end
end