class AWS::S3::ObjectCollection::BatchHelper

processes items in batches of 1k items @private

Public Class Methods

new(batch_size, &block) click to toggle source
# File lib/aws/s3/object_collection.rb, line 302
def initialize batch_size, &block
  @batch_size = batch_size
  @block = block
  @batch = []
end

Public Instance Methods

add(item) click to toggle source
# File lib/aws/s3/object_collection.rb, line 312
def add item
  @batch << item
  if @batch.size == @batch_size
    process_batch
    @batch = []
  end
  item
end
after_batch(&block) click to toggle source
# File lib/aws/s3/object_collection.rb, line 308
def after_batch &block
  @after_batch = block
end
complete!() click to toggle source
# File lib/aws/s3/object_collection.rb, line 321
def complete!
  process_batch unless @batch.empty?
end

Protected Instance Methods

process_batch() click to toggle source
# File lib/aws/s3/object_collection.rb, line 326
def process_batch
  response = @block.call(@batch)
  @after_batch.call(response) if @after_batch
end