class Processor::Data::BatchProcessor

TODO: Change it to be useful. Usually the external iterator is provided and results are mapped to it

Attributes

batch_size[R]

Public Class Methods

new(batch_size = 10) click to toggle source
# File lib/processor/data/batch_processor.rb, line 8
def initialize(batch_size = 10)
  @batch_size = batch_size
end

Public Instance Methods

fetch_batch() click to toggle source
# File lib/processor/data/batch_processor.rb, line 22
def fetch_batch
  @fetcher ||= query.each_slice(batch_size)
  # TODO get rid of .next enumeration here
  @fetcher.next
rescue StopIteration
  []
end
query() click to toggle source
# File lib/processor/data/batch_processor.rb, line 34
def query
  raise NotImplementedError
end
records() click to toggle source
# File lib/processor/data/batch_processor.rb, line 12
def records
  Enumerator.new do |result|
    while (batch = fetch_batch).any?
      batch.each do |record|
        result << record
      end
    end
  end
end
total_records() click to toggle source
# File lib/processor/data/batch_processor.rb, line 30
def total_records
  @total_records ||= query.count
end