Module: RemotelyExceptional::Handler

Defined in:
lib/remotely_exceptional/handler.rb

Overview

Mixin providing basic functionality required for matching and handling exceptions.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



73
74
75
# File 'lib/remotely_exceptional/handler.rb', line 73

def context
  @context
end

#exceptionObject (readonly)

Returns the value of attribute exception.



73
74
75
# File 'lib/remotely_exceptional/handler.rb', line 73

def exception
  @exception
end

Class Method Details

.included(includer) ⇒ Object

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

Parameters:

  • includer (Class, Module)

    The class or module that has included this module.



8
9
10
# File 'lib/remotely_exceptional/handler.rb', line 8

def self.included(includer)
  includer.extend(ClassMethods)
end

.new(super_class = Object) {|exception_instance| ... } ⇒ Class

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.

Parameters:

  • super_class (Class) (defaults to: Object)

    An optional super class to use when creating a new class with Handler behaviors.

Yield Parameters:

  • exception_instance (Exception)

    The exception instance that should be evaluated for a match.

Yield Returns:

  • (Boolean)

    A boolean value indicating whether or not the exception instance was matched.

Returns:

  • (Class)

    Returns a new class extended with Handler behaviors.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
# 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

Instance Method Details

#handleSymbol, Array<(Symbol, Object)>

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.

Returns:

  • (Symbol)

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

    :continue, :raise, :retry
  • (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]

Raises:

  • (NotImplementedError)

    Raised when the including class does not provide it’s own #handle instance method.



88
89
90
# File 'lib/remotely_exceptional/handler.rb', line 88

def handle
  raise NotImplementedError, "#{__method__} must be implemented by including class!"
end