Module: Easyop::Rescuable
- Defined in:
- lib/easyop/rescuable.rb
Overview
Lightweight rescue_from DSL, modelled after ActiveSupport::Rescuable. Works without ActiveSupport and can be used standalone.
Usage:
rescue_from SomeError, with: :handle_it
rescue_from OtherError, AnotherError do |e|
ctx.fail!(error: e.)
end
Handlers are checked in definition order (first match wins). Subclasses inherit their parent’s handlers.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#rescue_with_handler(exception) ⇒ Object
Attempt to handle ‘exception` with a registered handler.
Class Method Details
.included(base) ⇒ Object
14 15 16 |
# File 'lib/easyop/rescuable.rb', line 14 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#rescue_with_handler(exception) ⇒ Object
Attempt to handle ‘exception` with a registered handler. Returns true if handled, false if no matching handler found.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/easyop/rescuable.rb', line 45 def rescue_with_handler(exception) handler = handler_for_rescue(exception) return false unless handler case handler when Symbol then send(handler, exception) when Proc then instance_exec(exception, &handler) end true end |