123456789_123456789_123456789_123456789_123456789_

Module: ActiveSupport::ActionableError

Relationships & Source Files
Namespace Children
Modules:
Exceptions:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Concern
Defined in: activesupport/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 ActionableError module and invoke the action class macro to define the action. An action needs a name and a block to execute.

Class Method Summary

Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

append_features, prepend_features

DSL Calls

included

[ GitHub ]


16
17
18
# File 'activesupport/lib/active_support/actionable_error.rb', line 16

included do
  class_attribute :_actions, default: {}
end

Class Method Details

.actions(error)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/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)

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/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