Class: PackAPI::ValuesInBatches

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pack_api/values_in_batches.rb

Direct Known Subclasses

ValuesInBackgroundBatches

Instance Attribute Summary collapse

Instance Method Summary collapse

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_sizeObject (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

#kwargsObject (readonly)

Returns the value of attribute kwargs.



7
8
9
# File 'lib/pack_api/values_in_batches.rb', line 7

def kwargs
  @kwargs
end

#methodObject (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_attributesObject (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

#batchObject



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