Module: ActiveSupport::ActionableError

Extended by:
Concern
Included in:
ActiveRecord::PendingMigrationError
Defined in:
activesupport/lib/active_support/actionable_error.rb

Overview

Actionable errors let's 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

Methods included from Concern

append_features, class_methods, extended, included, prepend_features, prepended

Class Method Details

.actions(error) ⇒ Object

:nodoc:


18
19
20
21
22
23
24
25
# File 'activesupport/lib/active_support/actionable_error.rb', line 18

def self.actions(error) # :nodoc:
  case error
  when ActionableError, -> it { Class === it && it < ActionableError }
    error._actions
  else
    {}
  end
end

.dispatch(error, name) ⇒ Object

:nodoc:


27
28
29
30
31
# File 'activesupport/lib/active_support/actionable_error.rb', line 27

def self.dispatch(error, name) # :nodoc:
  actions(error).fetch(name).call
rescue KeyError
  raise NonActionable, "Cannot find action \"#{name}\""
end