Module: Easyop::Rescuable::ClassMethods

Defined in:
lib/easyop/rescuable.rb

Instance Method Summary collapse

Instance Method Details

#_all_rescue_handlersObject

Full ordered list: own handlers first, then ancestors’ (child wins).



36
37
38
39
40
# File 'lib/easyop/rescuable.rb', line 36

def _all_rescue_handlers
  parent = superclass
  parent_handlers = parent.respond_to?(:_all_rescue_handlers) ? parent._all_rescue_handlers : []
  _rescue_handlers + parent_handlers
end

#_rescue_handlersObject

Own handlers defined directly on this class (not inherited).



31
32
33
# File 'lib/easyop/rescuable.rb', line 31

def _rescue_handlers
  @_rescue_handlers ||= []
end

#rescue_from(*klasses, with: nil, &block) ⇒ Object

Register a handler for one or more exception classes. Pass ‘with: :method_name` or a block.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
# File 'lib/easyop/rescuable.rb', line 21

def rescue_from(*klasses, with: nil, &block)
  raise ArgumentError, "Provide `with:` or a block" unless with || block_given?

  handler = with || block
  klasses.each do |klass|
    _rescue_handlers << [klass, handler]
  end
end