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
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
Class Method Summary collapse
-
.included(includer) ⇒ Object
Actions that will be taken on any object that includes this module.
-
.new(super_class = Object) {|exception_instance| ... } ⇒ Class
Factory function for creating classes with Handler behaviors.
Instance Method Summary collapse
-
#handle ⇒ Symbol, Array<(Symbol, Object)>
Placeholder method, must be implemented by including class.
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
73 74 75 |
# File 'lib/remotely_exceptional/handler.rb', line 73 def context @context end |
#exception ⇒ Object (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.
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.
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
#handle ⇒ Symbol, 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.
88 89 90 |
# File 'lib/remotely_exceptional/handler.rb', line 88 def handle raise NotImplementedError, "#{__method__} must be implemented by including class!" end |