Class: Chewy::Type::Adapter::Sequel
- Defined in:
- lib/chewy/type/adapter/sequel.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#default_dataset ⇒ Object
readonly
Returns the value of attribute default_dataset.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #identify(obj) ⇒ Object
- #import(*args, &block) ⇒ Object
-
#initialize(*args) ⇒ Sequel
constructor
A new instance of Sequel.
- #load(*args) ⇒ Object
- #name ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*args) ⇒ Sequel
Returns a new instance of Sequel.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/chewy/type/adapter/sequel.rb', line 15 def initialize(*args) @options = args. if dataset? args.first dataset = args.first @target = dataset.model @default_dataset = dataset.unordered.unlimited else model = args.first @target = model @default_dataset = model.where(nil) end end |
Instance Attribute Details
#default_dataset ⇒ Object (readonly)
Returns the value of attribute default_dataset.
8 9 10 |
# File 'lib/chewy/type/adapter/sequel.rb', line 8 def default_dataset @default_dataset end |
Class Method Details
Instance Method Details
#identify(obj) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/chewy/type/adapter/sequel.rb', line 33 def identify(obj) if dataset? obj obj.select_map(target_pk) else Array.wrap(obj).map do |item| model?(item) ? item.pk : item end end end |
#import(*args, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/chewy/type/adapter/sequel.rb', line 43 def import(*args, &block) = args. batch_size = [:batch_size] || BATCH_SIZE if args.empty? import_dataset(default_dataset, batch_size, &block) elsif args.one? && dataset?(args.first) import_dataset(args.first, batch_size, &block) else import_models(args.flatten.compact, batch_size, &block) end end |
#load(*args) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/chewy/type/adapter/sequel.rb', line 56 def load(*args) = args. index_ids = args.flatten.map(&:id) # args contains index instances type_name = [:_type].type_name.to_sym additional_scope = [type_name].try(:[], :scope) || [:scope] dataset = select_by_ids(target, index_ids) if additional_scope.is_a?(Proc) index_ids.map!(&:to_s) dataset.instance_exec(&additional_scope).to_a.select do |model| index_ids.include? model.pk.to_s end else dataset.to_a end end |
#name ⇒ Object
29 30 31 |
# File 'lib/chewy/type/adapter/sequel.rb', line 29 def name @name ||= ([:name].presence || target.name).camelize.demodulize end |