aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2006-11-07 20:45:36 +0000
committerNicholas Seckar <nseckar@gmail.com>2006-11-07 20:45:36 +0000
commitad06514257e4472a986577ba7df66d9b8db8a2c2 (patch)
treebe644b4178b66a967de93a59cdb2e38323acd366 /activesupport/lib
parente1140f876ef2f2760753f681564cb025292c86f0 (diff)
downloadrails-ad06514257e4472a986577ba7df66d9b8db8a2c2.tar.gz
rails-ad06514257e4472a986577ba7df66d9b8db8a2c2.tar.bz2
rails-ad06514257e4472a986577ba7df66d9b8db8a2c2.zip
Update dependencies to delete partially loaded constants.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5464 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/dependencies.rb53
1 files changed, 34 insertions, 19 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 270496ab15..ad4e4da669 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -234,7 +234,7 @@ module Dependencies #:nodoc:
raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
end
- raise ArgumentError, "Expected #{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name)
+ raise ArgumentError, "#{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name)
qualified_name = qualified_name_for from_mod, const_name
path_suffix = qualified_name.underscore
@@ -301,6 +301,10 @@ module Dependencies #:nodoc:
# its execution. Constants may only be regarded as 'new' once -- so if the
# block calls +new_constants_in+ again, then the constants defined within the
# inner call will not be reported in this one.
+ #
+ # If the provided block does not run to completion, and instead raises an
+ # exception, any new constants are regarded as being only partially defined
+ # and will be removed immediately.
def new_constants_in(*descs)
log_call(*descs)
@@ -328,28 +332,39 @@ module Dependencies #:nodoc:
constant_watch_stack.concat watch_frames
- yield # Now yield to the code that is to define new constants.
-
- # Find the new constants.
- new_constants = watch_frames.collect do |mod_name, prior_constants|
- # Module still doesn't exist? Treat it as if it has no constants.
- next [] unless qualified_const_defined?(mod_name)
-
- mod = mod_name.constantize
- next [] unless mod.is_a? Module
- new_constants = mod.constants - prior_constants
+ aborting = true
+ begin
+ yield # Now yield to the code that is to define new constants.
+ aborting = false
+ ensure
+ # Find the new constants.
+ new_constants = watch_frames.collect do |mod_name, prior_constants|
+ # Module still doesn't exist? Treat it as if it has no constants.
+ next [] unless qualified_const_defined?(mod_name)
+
+ mod = mod_name.constantize
+ next [] unless mod.is_a? Module
+ new_constants = mod.constants - prior_constants
+
+ # Make sure no other frames takes credit for these constants.
+ constant_watch_stack.each do |frame_name, constants|
+ constants.concat new_constants if frame_name == mod_name
+ end
+
+ new_constants.collect do |suffix|
+ mod_name == "Object" ? suffix : "#{mod_name}::#{suffix}"
+ end
+ end.flatten
- # Make sure no other frames takes credit for these constants.
- constant_watch_stack.each do |frame_name, constants|
- constants.concat new_constants if frame_name == mod_name
- end
+ log "New constants: #{new_constants * ', '}"
- new_constants.collect do |suffix|
- mod_name == "Object" ? suffix : "#{mod_name}::#{suffix}"
+ if aborting
+ log "Error during loading, removing partially loaded constants "
+ new_constants.each { |name| remove_constant name }
+ new_constants.clear
end
- end.flatten
+ end
- log "New constants: #{new_constants * ', '}"
return new_constants
ensure
# Remove the stack frames that we added.