Module: RemotelyExceptional::Handler::ClassMethods

Defined in:
lib/remotely_exceptional/handler.rb

Overview

Class-level handler behaviors that will be added to any object that includes this module.

Instance Method Summary collapse

Instance Method Details

#===(exception) ⇒ Boolean

Used by Ruby’s rescue keyword to evaluate if an exception instance can be caught by this Class or Module. Delegates to #matcher.

Parameters:

  • exception (Exception)

    The exception instance that should be evaluated for a match.

Returns:

  • (Boolean)

    Returns a Boolean value indicating whether or not the exception instance matches this handler.



42
43
44
# File 'lib/remotely_exceptional/handler.rb', line 42

def ===(exception)
  matcher.call(exception)
end

#handle(exception = $!, context = {}) ⇒ Symbol

Factory method that takes in an exception and an optional Hash of additional contextual information and creates a new Handler instance from that data. The generated Handler instance is then used to handle the the exception.

Parameters:

  • exception (Exception) (defaults to: $!)

    The exception to handle. Defaults to $!.

  • context (Hash{Symbol=>Object}) (defaults to: {})

    An optional Hash of additional contextual information about the exception.

Returns:

  • (Symbol)

    Returns a symbol indicating what action should be taken to continue execution. Depending on the situation, valid values include:

    :continue, :raise, :retry


57
58
59
60
61
62
63
# File 'lib/remotely_exceptional/handler.rb', line 57

def handle(exception = $!, context = {})
  instance = new
  context, exception = exception, $! if exception.is_a?(Hash)
  instance.instance_variable_set(:@exception, exception)
  instance.instance_variable_set(:@context, context)
  instance.handle
end