module RemotelyExceptional::Handler::ClassMethods
Class-level handler behaviors that will be added to any object that includes this module.
Public Instance Methods
Used by Ruby’s rescue keyword to evaluate if an exception instance can be caught by this Class or Module. Delegates to {#matcher}.
@param exception [Exception] The exception instance that should be evaluated
for a match.
@return [Boolean] Returns a Boolean value indicating whether or not the
exception instance matches this handler.
# File lib/remotely_exceptional/handler.rb, line 42 def ===(exception) matcher.call(exception) end
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.
@param exception [Exception] The exception to handle. Defaults to $!. @param context [Hash{Symbol=>Object}] An optional Hash of additional
contextual information about the exception.
@return [Symbol] Returns a symbol indicating what action should be taken
to continue execution. Depending on the situation, valid values include: [:continue, :raise, :retry]
# 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
Private Instance Methods
The block used by the class to evaluate matching exceptions.
# File lib/remotely_exceptional/handler.rb, line 68 def matcher @matcher end