Removing duplication in callback normalization. #8157

Merged
merged 1 commit into from Nov 9, 2012

Projects

None yet

3 participants

@steveklabnik
Ruby on Rails member

These two things were 100% identical.

@steveklabnik steveklabnik Removing duplication in callback normalization.
These two things were 100% identical.
c4e3b0c
@rafaelfranca rafaelfranca merged commit 52538dd into rails:master Nov 9, 2012
@rafaelfranca
Ruby on Rails member

Thanks

@steveklabnik
Ruby on Rails member

Thank YOU ❤️

@egilburg egilburg commented on the diff Nov 9, 2012
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]
@egilburg
egilburg Nov 9, 2012

doesn't this line shadow the from in the argument list as the very first thing, making the argument dead code?

@steveklabnik
steveklabnik Nov 10, 2012

it's not 'dead code', we need to turn, for example, :only into options[:only]. It just so happens that :only is stored in a variable named from, which we then assign the result of options[from] to.

@steveklabnik
steveklabnik Nov 10, 2012

You are right in that we don't use the argument again, though.

@egilburg
egilburg Nov 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment