diff options
author | Genadi Samokovarov <gsamokovarov@gmail.com> | 2019-01-01 12:07:20 +0200 |
---|---|---|
committer | Genadi Samokovarov <gsamokovarov@gmail.com> | 2019-04-19 14:15:23 +0900 |
commit | 963fef7b37d6bc31dd385c92cbe8be934aa2871f (patch) | |
tree | 5e485a0ca86d3497c943dddb89ac4e633372b5d6 /activesupport/lib/active_support/actionable_error.rb | |
parent | a3110fe20bc418034332bd01165df7fe6f20258e (diff) | |
download | rails-963fef7b37d6bc31dd385c92cbe8be934aa2871f.tar.gz rails-963fef7b37d6bc31dd385c92cbe8be934aa2871f.tar.bz2 rails-963fef7b37d6bc31dd385c92cbe8be934aa2871f.zip |
Simplify the ActionableError.{dispatch,action} boundries
Diffstat (limited to 'activesupport/lib/active_support/actionable_error.rb')
-rw-r--r-- | activesupport/lib/active_support/actionable_error.rb | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/activesupport/lib/active_support/actionable_error.rb b/activesupport/lib/active_support/actionable_error.rb index be4972759b..88a3eaa514 100644 --- a/activesupport/lib/active_support/actionable_error.rb +++ b/activesupport/lib/active_support/actionable_error.rb @@ -15,8 +15,8 @@ module ActiveSupport NonActionable = Class.new(StandardError) - NoActions = Hash.new do |_, label| # :nodoc: - raise NonActionable, "Cannot find action \"#{label}\" for #{self}" + NoActions = Hash.new do |_, name| # :nodoc: + raise NonActionable, "Cannot find action \"#{name}\"" end included do @@ -25,19 +25,15 @@ module ActiveSupport def self.actions(error) # :nodoc: case error - when String - actions(error.constantize) when ActionableError, -> it { Class === it && it < ActionableError } error._actions - when Exception - NoActions else - raise NonActionable, "#{error} is non-actionable" + NoActions end end - def self.dispatch(error, label) # :nodoc: - actions(error)[label].call + def self.dispatch(error, name) # :nodoc: + actions(error.is_a?(String) ? error.constantize : error)[name].call end module ClassMethods @@ -50,8 +46,8 @@ module ActiveSupport # ActiveRecord::Tasks::DatabaseTasks.migrate # end # end - def action(label, &block) - _actions[label] = block + def action(name, &block) + _actions[name] = block end end end |