Module: Genius::Errors::DynamicRescue
- Defined in:
- lib/genius/api/errors.rb
Overview
Genius::Errors::DynamicRescue module is used to call dynamically exceptions to each method in module or class, defined in Genius::Errors scope.
Class Method Summary collapse
-
.rescue(klass) ⇒ Array
Wraps singleton methods of
klasswith exception handling via DynamicRescue.rescue_from. -
.rescue_from(meths, klass, exception) ⇒ Array
Redefines each method in
methsonklassto rescueexceptionand yield to the block.
Class Method Details
.rescue(klass) ⇒ Array
Wraps singleton methods of klass with exception handling via rescue_from.
131 132 133 134 135 136 |
# File 'lib/genius/api/errors.rb', line 131 def rescue(klass) DynamicRescue.rescue_from klass.singleton_methods, klass, GeniusExceptionSuperClass do |e| puts "Error description: #{e.msg}\nException type: #{e.exception_type}" # @todo make raise ExceptionKlass end end |
.rescue_from(meths, klass, exception) ⇒ Array
Redefines each method in meths on klass to rescue exception and yield to the block.
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/genius/api/errors.rb', line 145 def rescue_from(meths, klass, exception, &) meths.each do |meth| old = klass.singleton_method(meth) klass.define_singleton_method(meth) do |*args, **kwargs| old.unbind.bind(klass).call(*args, **kwargs) # steep:ignore rescue exception => e yield(e) end end end |