module RemotelyExceptional::Handler

Mixin providing basic functionality required for matching and handling exceptions.

Attributes

context[R]
exception[R]

Public Class Methods

included(includer) click to toggle source

Actions that will be taken on any object that includes this module.

@param includer [Class,Module] The class or module that has included this

module.
# File lib/remotely_exceptional/handler.rb, line 8
def self.included(includer)
  includer.extend(ClassMethods)
end
new(super_class = Object, &block) click to toggle source

Factory function for creating classes with Handler behaviors. Creates a new class with Handler behaviors from the given super class and block. By default the super class of the new class will be Object. The given block will be used as the matcher of the generated class.

@param super_class [Class] An optional super class to use when creating a

new class with Handler behaviors.

@yieldparam [Exception] exception_instance The exception instance that

should be evaluated for a match.

@yieldreturn [Boolean] A boolean value indicating whether or not the

exception instance was matched.

@return [Class] Returns a new class extended with Handler behaviors.

# File lib/remotely_exceptional/handler.rb, line 24
def self.new(super_class = Object, &block)
  raise ArgumentError, "Block required" unless block_given?
  handler_class = Class.new(super_class)
  handler_class.send(:include, self)
  handler_class.instance_variable_set(:@matcher, block)
  handler_class
end

Public Instance Methods

handle() click to toggle source

Placeholder method, must be implemented by including class. Should encapsulate the logic required to handle an exception matced by the class. Should take no arguments.

@raise [NotImplementedError] Raised when the including class does not

provide it's own #handle instance method.

@return [Symbol] Returns a symbol indicating what action should be taken

to continue execution. Depending on the situation, valid values include:
[:continue, :raise, :retry]

@return [Array<(Symbol, Object)>] Returns a symbol indicating what action

should be taken to continue execution and an object that should be used as
the result of the rescue operation. Depending on the situation, valid
action values include: [:continue, :raise, :retry]
# File lib/remotely_exceptional/handler.rb, line 88
def handle
  raise NotImplementedError, "#{__method__} must be implemented by including class!"
end