Permalink
Browse files

Merge pull request #8157 from steveklabnik/remove_callback_duplication

Removing duplication in callback normalization.
  • Loading branch information...
rafaelfranca committed Nov 9, 2012
2 parents dbb39e5 + c4e3b0c commit 52538dda134fc287d0d903c0b3e17e5c0f9177a9
Showing with 8 additions and 7 deletions.
  1. +8 −7 actionpack/lib/abstract_controller/callbacks.rb
@@ -29,13 +29,14 @@ module ClassMethods
# * <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

0 comments on commit 52538dd

Please sign in to comment.