Module: Sidekiq::Job::Iterable::Enumerators
- Included in:
- Sidekiq::Job::Iterable
- Defined in:
- lib/sidekiq/job/iterable/enumerators.rb
Instance Method Summary collapse
-
#active_record_batches_enumerator(relation, cursor:, **options) ⇒ Object
Builds Enumerator from ‘ActiveRecord::Relation` and enumerates on batches of records.
-
#active_record_records_enumerator(relation, cursor:, **options) ⇒ ActiveRecordEnumerator
Builds Enumerator from ‘ActiveRecord::Relation`.
-
#active_record_relations_enumerator(relation, cursor:, **options) ⇒ Object
Builds Enumerator from ‘ActiveRecord::Relation` and enumerates on batches, yielding `ActiveRecord::Relation`s.
-
#array_enumerator(array, cursor:) ⇒ Enumerator
Builds Enumerator object from a given array, using
cursor
as an offset. -
#csv_batches_enumerator(csv, cursor:, **options) ⇒ Object
Builds Enumerator from a CSV file and enumerates on batches of records.
-
#csv_enumerator(csv, cursor:) ⇒ Object
Builds Enumerator from a CSV file.
Instance Method Details
#active_record_batches_enumerator(relation, cursor:, **options) ⇒ Object
Builds Enumerator from ‘ActiveRecord::Relation` and enumerates on batches of records. Each Enumerator tick moves the cursor `:batch_size` rows forward.
68 69 70 |
# File 'lib/sidekiq/job/iterable/enumerators.rb', line 68 def active_record_batches_enumerator(relation, cursor:, **) ActiveRecordEnumerator.new(relation, cursor: cursor, **).batches end |
#active_record_records_enumerator(relation, cursor:, **options) ⇒ ActiveRecordEnumerator
Builds Enumerator from ‘ActiveRecord::Relation`. Each Enumerator tick moves the cursor one row forward.
46 47 48 |
# File 'lib/sidekiq/job/iterable/enumerators.rb', line 46 def active_record_records_enumerator(relation, cursor:, **) ActiveRecordEnumerator.new(relation, cursor: cursor, **).records end |
#active_record_relations_enumerator(relation, cursor:, **options) ⇒ Object
Builds Enumerator from ‘ActiveRecord::Relation` and enumerates on batches, yielding `ActiveRecord::Relation`s.
90 91 92 |
# File 'lib/sidekiq/job/iterable/enumerators.rb', line 90 def active_record_relations_enumerator(relation, cursor:, **) ActiveRecordEnumerator.new(relation, cursor: cursor, **).relations end |
#array_enumerator(array, cursor:) ⇒ Enumerator
Builds Enumerator object from a given array, using cursor
as an offset.
20 21 22 23 24 25 |
# File 'lib/sidekiq/job/iterable/enumerators.rb', line 20 def array_enumerator(array, cursor:) raise ArgumentError, "array must be an Array" unless array.is_a?(Array) x = array.each_with_index.drop(cursor || 0) x.to_enum { x.size } end |
#csv_batches_enumerator(csv, cursor:, **options) ⇒ Object
Builds Enumerator from a CSV file and enumerates on batches of records.
129 130 131 |
# File 'lib/sidekiq/job/iterable/enumerators.rb', line 129 def csv_batches_enumerator(csv, cursor:, **) CsvEnumerator.new(csv).batches(cursor: cursor, **) end |
#csv_enumerator(csv, cursor:) ⇒ Object
Builds Enumerator from a CSV file.
109 110 111 |
# File 'lib/sidekiq/job/iterable/enumerators.rb', line 109 def csv_enumerator(csv, cursor:) CsvEnumerator.new(csv).rows(cursor: cursor) end |