diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-11-09 05:52:28 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-11-09 05:52:28 -0800 |
commit | 52538dda134fc287d0d903c0b3e17e5c0f9177a9 (patch) | |
tree | 1a8921018f9ae52e76ae3d1cad1171608e749378 /actionpack/lib | |
parent | dbb39e53414294818c056f1db336471dd347d413 (diff) | |
parent | c4e3b0cd8b3208bf692a5e278d76c9e26745a4eb (diff) | |
download | rails-52538dda134fc287d0d903c0b3e17e5c0f9177a9.tar.gz rails-52538dda134fc287d0d903c0b3e17e5c0f9177a9.tar.bz2 rails-52538dda134fc287d0d903c0b3e17e5c0f9177a9.zip |
Merge pull request #8157 from steveklabnik/remove_callback_duplication
Removing duplication in callback normalization.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/abstract_controller/callbacks.rb | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb index 5705ab590c..02ac111392 100644 --- a/actionpack/lib/abstract_controller/callbacks.rb +++ b/actionpack/lib/abstract_controller/callbacks.rb @@ -29,13 +29,14 @@ module AbstractController # * <tt>only</tt> - The callback should be run only for this action # * <tt>except</tt> - The callback should be run for all actions except this action def _normalize_callback_options(options) - if only = options[:only] - only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ") - options[:if] = Array(options[:if]) << only - end - if except = options[:except] - except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ") - options[:unless] = Array(options[:unless]) << except + _normalize_callback_option(options, :only, :if) + _normalize_callback_option(options, :except, :unless) + end + + def _normalize_callback_option(options, from, to) # :nodoc: + if from = options[from] + from = Array(from).map {|o| "action_name == '#{o}'"}.join(" || ") + options[to] = Array(options[to]) << from end end |