1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Improve code readability in ActiveSupport::Dependencies

This commit is contained in:
Aaron Ang 2016-03-15 15:13:14 +01:00
parent 758df587cc
commit 901a407512

View file

@ -656,16 +656,17 @@ module ActiveSupport #:nodoc:
# and will be removed immediately. # and will be removed immediately.
def new_constants_in(*descs) def new_constants_in(*descs)
constant_watch_stack.watch_namespaces(descs) constant_watch_stack.watch_namespaces(descs)
aborting = true success = false
begin begin
yield # Now yield to the code that is to define new constants. yield # Now yield to the code that is to define new constants.
aborting = false success = true
ensure ensure
new_constants = constant_watch_stack.new_constants new_constants = constant_watch_stack.new_constants
return new_constants unless aborting return new_constants if success
# Remove partially loaded constants.
new_constants.each { |c| remove_constant(c) } new_constants.each { |c| remove_constant(c) }
end end
end end
@ -734,7 +735,7 @@ module ActiveSupport #:nodoc:
begin begin
constantized = parent.const_get(to_remove, false) constantized = parent.const_get(to_remove, false)
rescue NameError rescue NameError
# Skip when const is unreachable. # The constant is no longer reachable, just skip it.
return return
else else
constantized.before_remove_const if constantized.respond_to?(:before_remove_const) constantized.before_remove_const if constantized.respond_to?(:before_remove_const)
@ -744,7 +745,7 @@ module ActiveSupport #:nodoc:
begin begin
parent.instance_eval { remove_const to_remove } parent.instance_eval { remove_const to_remove }
rescue NameError rescue NameError
# Skip when const is unreachable. # The constant is no longer reachable, just skip it.
end end
end end
end end