Module: Philiprehberger::CsvKit::ErrorHandler

Included in:
Processor
Defined in:
lib/philiprehberger/csv_kit/error_handler.rb

Overview

Mixin for per-row error handling and max-error tracking.

Instance Method Summary collapse

Instance Method Details

#errorsArray<Hash>

Returns collected errors from the last run.

Returns:

  • (Array<Hash>)

    error details



27
28
29
# File 'lib/philiprehberger/csv_kit/error_handler.rb', line 27

def errors
  @errors ||= []
end

#max_errors(limit) ⇒ self

Set a maximum number of errors before aborting.

Parameters:

  • limit (Integer)

    max errors allowed

Returns:

  • (self)


19
20
21
22
# File 'lib/philiprehberger/csv_kit/error_handler.rb', line 19

def max_errors(limit)
  @max_errors = limit
  self
end

#on_error {|Hash, StandardError| ... } ⇒ Object

Configure a per-row error handler.

Yields:

  • (Hash, StandardError)

    the row data and the error

Yield Returns:

  • (:skip, :abort)

    action to take



11
12
13
# File 'lib/philiprehberger/csv_kit/error_handler.rb', line 11

def on_error(&block)
  @error_handler = block
end