class Processor::Data::ActiveRecordBatchProcessor
Attributes
batch_size[R]
output[R]
presenter[R]
source[R]
Public Class Methods
new(source:, presenter: -> { Hash.new }
click to toggle source
# File lib/processor/data/active_record_batch_processor.rb, line 8 def initialize(source:, presenter: -> { Hash.new }, output:, batch_size: 1000) @source = source @presenter = presenter @output = output @batch_size = batch_size end
Public Instance Methods
finalize()
click to toggle source
# File lib/processor/data/active_record_batch_processor.rb, line 28 def finalize output.close end
process(record)
click to toggle source
# File lib/processor/data/active_record_batch_processor.rb, line 19 def process(record) output.write presenter.call(record) "OK" end
record_id(record)
click to toggle source
# File lib/processor/data/active_record_batch_processor.rb, line 24 def record_id(record) record.id end
records()
click to toggle source
# File lib/processor/data/active_record_batch_processor.rb, line 15 def records source.find_each(batch_size: batch_size) end
total_records()
click to toggle source
# File lib/processor/data/active_record_batch_processor.rb, line 32 def total_records @total_records ||= source.count end