Sha256: 7ba2494e367394262e5c1b815d80b93660c08f071fdda0e9577e38961814dc82

Contents?: true

Size: 679 Bytes

Versions: 4

Compression:

Stored size: 679 Bytes

Contents

module Cascade
  class ErrorHandler
    HANDLING_EXCEPTIONS = [IsoCountryCodes::UnknownCodeError, IndexError]
    DEFAULT_ERROR_STORE = ->(row, reason) do
      @errors ||= []
      @errors << [row, reason]
    end

    def initialize(options = {})
      @error_store = options.fetch(:error_store) { DEFAULT_ERROR_STORE }
    end

    # Runs passed block with catching throwing errors and storing in ErrorStore
    #
    # @param row [Hash] the object retrieved from CSV to store it in case of
    # problems with processing
    def with_errors_handling(row)
      yield
    rescue *HANDLING_EXCEPTIONS => exception
      @error_store.call(row, exception.to_s)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cascade-rb-0.1.4 lib/cascade/error_handler.rb
cascade-rb-0.1.2 lib/cascade/error_handler.rb
cascade-rb-0.1.1 lib/cascade/error_handler.rb
cascade-rb-0.1.0 lib/cascade/error_handler.rb