Class: PackAPI::ValuesInBatches
- Inherits:
-
Object
- Object
- PackAPI::ValuesInBatches
- Includes:
- Enumerable
- Defined in:
- lib/pack_api/values_in_batches.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#kwargs ⇒ Object
readonly
Returns the value of attribute kwargs.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#optional_attributes ⇒ Object
readonly
Returns the value of attribute optional_attributes.
Instance Method Summary collapse
- #batch ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(method:, batch_size:, optional_attributes: nil, **kwargs) ⇒ ValuesInBatches
constructor
A new instance of ValuesInBatches.
Constructor Details
#initialize(method:, batch_size:, optional_attributes: nil, **kwargs) ⇒ ValuesInBatches
Returns a new instance of ValuesInBatches.
9 10 11 12 13 14 |
# File 'lib/pack_api/values_in_batches.rb', line 9 def initialize(method:, batch_size:, optional_attributes: nil, **kwargs) @method = method @batch_size = batch_size @optional_attributes = optional_attributes @kwargs = kwargs end |
Instance Attribute Details
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
7 8 9 |
# File 'lib/pack_api/values_in_batches.rb', line 7 def batch_size @batch_size end |
#kwargs ⇒ Object (readonly)
Returns the value of attribute kwargs.
7 8 9 |
# File 'lib/pack_api/values_in_batches.rb', line 7 def kwargs @kwargs end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
7 8 9 |
# File 'lib/pack_api/values_in_batches.rb', line 7 def method @method end |
#optional_attributes ⇒ Object (readonly)
Returns the value of attribute optional_attributes.
7 8 9 |
# File 'lib/pack_api/values_in_batches.rb', line 7 def optional_attributes @optional_attributes end |
Instance Method Details
#batch ⇒ Object
28 29 30 |
# File 'lib/pack_api/values_in_batches.rb', line 28 def batch @result.value end |
#each(&block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pack_api/values_in_batches.rb', line 16 def each(&block) make_next_batch_available return if batch.empty? loop do batch.each_with_index { |item, index| process_item(index, item, block) } break if next_batch_cursor.blank? make_next_batch_available end end |