mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Replace nested ifs with case/when
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
parent
4c4c7a272f
commit
1ce9b73e5c
1 changed files with 43 additions and 45 deletions
|
@ -178,8 +178,8 @@ module ActiveSupport
|
|||
# options[0] is the compiled form of supplied conditions
|
||||
# options[1] is the "end" for the conditional
|
||||
#
|
||||
if @kind == :before || @kind == :around
|
||||
if @kind == :before
|
||||
case @kind
|
||||
when :before
|
||||
# if condition # before_save :filter_name, :if => :condition
|
||||
# filter_name
|
||||
# end
|
||||
|
@ -191,7 +191,7 @@ module ActiveSupport
|
|||
RUBY_EVAL
|
||||
|
||||
[@compiled_options[0], filter, @compiled_options[1]].compact.join("\n")
|
||||
else
|
||||
when :around
|
||||
# Compile around filters with conditions into proxy methods
|
||||
# that contain the conditions.
|
||||
#
|
||||
|
@ -222,24 +222,22 @@ module ActiveSupport
|
|||
"#{name}(halted) do"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This will supply contents for around and after filters, but not
|
||||
# before filters (for the backward pass).
|
||||
def end(key=nil, object=nil)
|
||||
return if key && !object.send("_one_time_conditions_valid_#{@callback_id}?")
|
||||
|
||||
if @kind == :around || @kind == :after
|
||||
case @kind
|
||||
when :after
|
||||
# if condition # after_save :filter_name, :if => :condition
|
||||
# filter_name
|
||||
# end
|
||||
if @kind == :after
|
||||
[@compiled_options[0], @filter, @compiled_options[1]].compact.join("\n")
|
||||
else
|
||||
when :around
|
||||
"end"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
Loading…
Reference in a new issue