Class: BulkProcessor::CSVProcessor::RowProcessor
- Inherits:
-
Object
- Object
- BulkProcessor::CSVProcessor::RowProcessor
- Defined in:
- lib/bulk_processor/csv_processor/row_processor.rb
Overview
An abstract implementation of the RowProcessor role. This class implements ‘#results` by returning an array of `Results`. To subclass, just implement `#process` to handle the row.
The row will be considered a failure by default. After a row is successfully processed, set ‘self.successful = true`. If there are any messages that should be passed back to the Handler, add them to the `#errors` array.
You can optionally override ‘#primary_keys` so that the result returned has more natural identifiers than just the row number. For example, you setting this to [’species’, ‘name’] (for the PetRowProcessor example from the README), the result would have ‘#primary_attributes` like
{ 'species' => 'dog', 'name' => 'Fido' }
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
-
#initialize(row, row_num:, payload:) ⇒ RowProcessor
constructor
A new instance of RowProcessor.
- #process! ⇒ Object
- #result ⇒ Object
- #successful? ⇒ Boolean
Constructor Details
#initialize(row, row_num:, payload:) ⇒ RowProcessor
21 22 23 24 25 26 27 |
# File 'lib/bulk_processor/csv_processor/row_processor.rb', line 21 def initialize(row, row_num:, payload:) @row = row @row_num = row_num @payload = payload @successful = false = [] end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
19 20 21 |
# File 'lib/bulk_processor/csv_processor/row_processor.rb', line 19 def end |
Instance Method Details
#process! ⇒ Object
29 30 31 32 |
# File 'lib/bulk_processor/csv_processor/row_processor.rb', line 29 def process! raise NotImplementedError, "#{self.class.name} must implement #{__method__}" end |
#result ⇒ Object
38 39 40 41 |
# File 'lib/bulk_processor/csv_processor/row_processor.rb', line 38 def result Result.new(messages: , row_num: row_num, primary_attributes: primary_attrs, successful: @successful) end |
#successful? ⇒ Boolean
34 35 36 |
# File 'lib/bulk_processor/csv_processor/row_processor.rb', line 34 def successful? @successful end |