Class: CsvPiper::Processors::CollectErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_piper/processors/collect_errors.rb

Overview

Collects errors for use after processing. Instantiate and keep a reference, then once processing complete retrieve errors through #errors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollectErrors

Returns a new instance of CollectErrors.



9
10
11
# File 'lib/csv_piper/processors/collect_errors.rb', line 9

def initialize
  @errors = {}
end

Instance Attribute Details

#errorsObject (readonly)

@return Holds all of the errors for each row that was processed { row_index => { errors_key => array_of_errors } }



8
9
10
# File 'lib/csv_piper/processors/collect_errors.rb', line 8

def errors
  @errors
end

Instance Method Details

#process(_source, transformed, row_errors) ⇒ Object



13
14
15
16
# File 'lib/csv_piper/processors/collect_errors.rb', line 13

def process(_source, transformed, row_errors)
  @errors[row_errors.row_index] = row_errors.errors unless row_errors.empty?
  [transformed, errors]
end