Module: ActiveSupport::ActionableError
- Extended by:
- Concern
- Defined in:
- lib/active_support/actionable_error.rb
Overview
Actionable Errors
Actionable errors lets you define actions to resolve an error.
To make an error actionable, include the ActiveSupport::ActionableError
module and invoke the action
class macro to define the action. An action needs a name and a block to execute.
Defined Under Namespace
Modules: ClassMethods Classes: NonActionable
Class Method Summary collapse
-
.actions(error) ⇒ Object
:nodoc:.
-
.dispatch(error, name) ⇒ Object
:nodoc:.
Methods included from Concern
append_features, class_methods, extended, included, prepend_features, prepended
Class Method Details
.actions(error) ⇒ Object
:nodoc:
20 21 22 23 24 25 26 27 |
# File 'lib/active_support/actionable_error.rb', line 20 def self.actions(error) # :nodoc: case error when ActionableError, -> it { Class === it && it < ActionableError } error._actions else {} end end |
.dispatch(error, name) ⇒ Object
:nodoc:
29 30 31 32 33 |
# File 'lib/active_support/actionable_error.rb', line 29 def self.dispatch(error, name) # :nodoc: actions(error).fetch(name).call rescue KeyError raise NonActionable, "Cannot find action \"#{name}\"" end |