Class: BulkProcessor::ProcessCSV

Inherits:
Object
  • Object
show all
Defined in:
lib/bulk_processor/process_csv.rb

Instance Method Summary collapse

Constructor Details

#initialize(processor_class, payload, key) ⇒ ProcessCSV

Returns a new instance of ProcessCSV.



3
4
5
6
7
# File 'lib/bulk_processor/process_csv.rb', line 3

def initialize(processor_class, payload, key)
  @processor_class = processor_class
  @payload = payload
  @key = key
end

Instance Method Details

#performObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/bulk_processor/process_csv.rb', line 9

def perform
  file = BulkProcessor.config.file_class.new(key)
  file.open do |f|
    csv = CSV.parse(f.read, headers: true)
    processor = processor_class.new(csv, payload: payload.merge('key' => key))
    processor.start
  end
ensure
  file.try(:delete)
end