Class: Cascade::ErrorHandler

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

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from Configuration

configuration, define_setting

Constructor Details

#initialize(options = {}) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



15
16
17
18
19
20
# File 'lib/cascade/error_handler.rb', line 15

def initialize(options = {})
  @error_store = options.fetch(:error_store) { DEFAULT_ERROR_STORE }
  @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



26
27
28
29
30
31
# File 'lib/cascade/error_handler.rb', line 26

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