Sha256: 3802d52b28495ce89f188c18a7a99cf047a78132f1fd13ae433d6055ddc0e00e

Contents?: true

Size: 624 Bytes

Versions: 13

Compression:

Stored size: 624 Bytes

Contents

module Chanko
  class ExceptionHandler
    def self.handle(*args)
      new(*args).handle
    end

    attr_reader :exception, :unit

    def initialize(exception, unit = nil)
      @exception = exception
      @unit      = unit
    end

    def handle
      if propagated?
        raise exception
      else
        log
        raise exception if raised?
      end
    end

    private

    def propagated?
      Config.propagated_errors.any? {|klass| exception.is_a?(klass) }
    end

    def raised?
      unit.try(:raise_error?) || Config.raise_error
    end

    def log
      Logger.debug(exception)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
chanko-2.3.0 lib/chanko/exception_handler.rb
chanko-2.2.1 lib/chanko/exception_handler.rb
chanko-2.2.0 lib/chanko/exception_handler.rb
chanko-2.1.1 lib/chanko/exception_handler.rb
chanko-2.1.0 lib/chanko/exception_handler.rb
chanko-2.0.8 lib/chanko/exception_handler.rb
chanko-2.0.7 lib/chanko/exception_handler.rb
chanko-2.0.6 lib/chanko/exception_handler.rb
chanko-2.0.5 lib/chanko/exception_handler.rb
chanko-2.0.4 lib/chanko/exception_handler.rb
chanko-2.0.3 lib/chanko/exception_handler.rb
chanko-2.0.2 lib/chanko/exception_handler.rb
chanko-2.0.1 lib/chanko/exception_handler.rb