Class: Sidekiq::Job::Iterable::ActiveRecordEnumerator Private
- Inherits:
-
Object
- Object
- Sidekiq::Job::Iterable::ActiveRecordEnumerator
- Defined in:
- lib/sidekiq/job/iterable/active_record_enumerator.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #batches ⇒ Object private
-
#initialize(relation, cursor: nil, **options) ⇒ ActiveRecordEnumerator
constructor
private
A new instance of ActiveRecordEnumerator.
- #records ⇒ Object private
- #relations ⇒ Object private
Constructor Details
#initialize(relation, cursor: nil, **options) ⇒ ActiveRecordEnumerator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ActiveRecordEnumerator.
8 9 10 11 12 |
# File 'lib/sidekiq/job/iterable/active_record_enumerator.rb', line 8 def initialize(relation, cursor: nil, **) @relation = relation @cursor = cursor @options = end |
Instance Method Details
#batches ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 25 26 27 28 |
# File 'lib/sidekiq/job/iterable/active_record_enumerator.rb', line 22 def batches Enumerator.new(-> { @relation.count }) do |yielder| @relation.find_in_batches(**@options, start: @cursor) do |batch| yielder.yield(batch, batch.first.id) end end end |
#records ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 17 18 19 20 |
# File 'lib/sidekiq/job/iterable/active_record_enumerator.rb', line 14 def records Enumerator.new(-> { @relation.count }) do |yielder| @relation.find_each(**@options, start: @cursor) do |record| yielder.yield(record, record.id) end end end |
#relations ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sidekiq/job/iterable/active_record_enumerator.rb', line 30 def relations Enumerator.new(-> { relations_size }) do |yielder| # Convenience to use :batch_size for all the # ActiveRecord batching methods. = @options.dup [:of] ||= .delete(:batch_size) @relation.in_batches(**, start: @cursor) do |relation| first_record = relation.first yielder.yield(relation, first_record.id) end end end |