Class: Cascade::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/cascade/error_handler.rb

Constant Summary collapse

HANDLING_EXCEPTIONS =
[IndexError].freeze
DEFAULT_ERROR_STORE =
lambda do |row, exception|
  @errors ||= []
  @errors << [row, exception.to_s]
end

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



11
12
13
14
15
16
17
# File 'lib/cascade/error_handler.rb', line 11

def initialize(options = {})
  @error_store = options.fetch(:error_store) { DEFAULT_ERROR_STORE }
  @raise_parse_errors = options.fetch(:raise_parse_errors, false)
  @handling_exceptions = options.fetch(:handling_exceptions) do
    HANDLING_EXCEPTIONS
  end
end

Instance Method Details

#with_errors_handling(row) ⇒ Object

Runs passed block with catching throwing errors and storing in ErrorStore

problems with processing

Parameters:

  • row (Hash)

    the object retrieved from CSV to store it in case of



23
24
25
26
27
28
# File 'lib/cascade/error_handler.rb', line 23

def with_errors_handling(row)
  yield
rescue *@handling_exceptions => exception
  @error_store.call(row, exception)
  raise exception if @raise_parse_errors
end