Class: Sequel::Extensions::Batches::Yielder
- Inherits:
-
Object
- Object
- Sequel::Extensions::Batches::Yielder
- Defined in:
- lib/sequel/extensions/batches/yielder.rb
Instance Attribute Summary collapse
-
#ds ⇒ Object
Returns the value of attribute ds.
-
#finish ⇒ Object
Returns the value of attribute finish.
-
#of ⇒ Object
Returns the value of attribute of.
-
#order ⇒ Object
Returns the value of attribute order.
-
#pk ⇒ Object
writeonly
Sets the attribute pk.
-
#start ⇒ Object
Returns the value of attribute start.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(ds:, **options) ⇒ Yielder
constructor
A new instance of Yielder.
Constructor Details
#initialize(ds:, **options) ⇒ Yielder
Returns a new instance of Yielder.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sequel/extensions/batches/yielder.rb', line 8 def initialize(ds:, **) self.ds = ds.unordered self.pk = .delete(:pk) self.of = .delete(:of) || 1000 self.start = .delete(:start) self.finish = .delete(:finish) self.order = .delete(:order) || :asc raise ArgumentError, ":order must be :asc or :desc, got #{order.inspect}" unless %i[asc desc].include?(order) raise ArgumentError, "unknown options: #{.keys.inspect}" if .any? end |
Instance Attribute Details
#ds ⇒ Object
Returns the value of attribute ds.
5 6 7 |
# File 'lib/sequel/extensions/batches/yielder.rb', line 5 def ds @ds end |
#finish ⇒ Object
Returns the value of attribute finish.
5 6 7 |
# File 'lib/sequel/extensions/batches/yielder.rb', line 5 def finish @finish end |
#of ⇒ Object
Returns the value of attribute of.
5 6 7 |
# File 'lib/sequel/extensions/batches/yielder.rb', line 5 def of @of end |
#order ⇒ Object
Returns the value of attribute order.
5 6 7 |
# File 'lib/sequel/extensions/batches/yielder.rb', line 5 def order @order end |
#pk=(value) ⇒ Object
Sets the attribute pk
6 7 8 |
# File 'lib/sequel/extensions/batches/yielder.rb', line 6 def pk=(value) @pk = value end |
#start ⇒ Object
Returns the value of attribute start.
5 6 7 |
# File 'lib/sequel/extensions/batches/yielder.rb', line 5 def start @start end |
Instance Method Details
#call ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sequel/extensions/batches/yielder.rb', line 20 def call base_ds = setup_base_ds or return return enum_for(:call) unless block_given? current_instance = nil loop do working_ds = if current_instance base_ds.where(generate_conditions(current_instance.to_h, sign: sign_from_exclusive)) else base_ds end working_ds_pk = working_ds.select(*qualified_pk).order(*order_by(qualified: true)).limit(of) current_instance = db.from(working_ds_pk).select(*pk).order(*order_by).last or break working_ds = working_ds.where(generate_conditions(current_instance.to_h, sign: sign_to_inclusive)) yield working_ds end end |