diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2006-10-14 20:27:29 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2006-10-14 20:27:29 +0000 |
commit | 4257fd6970cd7d5843e462c4ac099cc639a81923 (patch) | |
tree | ae7ac9273c982b7f9e5355a2d77c80bf61b605bc /activesupport/lib/active_support/dependencies.rb | |
parent | ef6921628d4906fcd2945f2f90b050ff5b5ec258 (diff) | |
download | rails-4257fd6970cd7d5843e462c4ac099cc639a81923.tar.gz rails-4257fd6970cd7d5843e462c4ac099cc639a81923.tar.bz2 rails-4257fd6970cd7d5843e462c4ac099cc639a81923.zip |
Rename overlapping test names
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5302 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/dependencies.rb')
-rw-r--r-- | activesupport/lib/active_support/dependencies.rb | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 4a4861220e..f1be0489df 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -38,6 +38,11 @@ module Dependencies #:nodoc: mattr_accessor :autoloaded_constants self.autoloaded_constants = [] + # An array of constant names that need to be unloaded on every request. Used + # to allow arbitrary constants to be marked for unloading. + mattr_accessor :explicitly_unloadable_constants + self.explicitly_unloadable_constants = [] + # Set to true to enable logging of const_missing and file loads mattr_accessor :log_activity self.log_activity = false @@ -60,7 +65,7 @@ module Dependencies #:nodoc: def clear log_call loaded.clear - remove_autoloaded_constants! + remove_unloadable_constants! end def require_or_load(file_name, const_path = nil) @@ -252,21 +257,12 @@ module Dependencies #:nodoc: end end - # Remove the constants that have been autoloaded. - def remove_autoloaded_constants! - until autoloaded_constants.empty? - const = autoloaded_constants.shift - next unless qualified_const_defined? const - names = const.split('::') - if names.size == 1 || names.first.empty? # It's under Object - parent = Object - else - parent = (names[0..-2] * '::').constantize - end - log "removing constant #{const}" - parent.send :remove_const, names.last - true - end + # Remove the constants that have been autoloaded, and those that have been + # marked for unloading. + def remove_unloadable_constants! + autoloaded_constants.each { |const| remove_constant const } + autoloaded_constants.clear + explicitly_unloadable_constants.each { |const| remove_constant const } end # Determine if the given constant has been automatically loaded. @@ -276,6 +272,21 @@ module Dependencies #:nodoc: return autoloaded_constants.include?(name) end + # Will the provided constant descriptor be unloaded? + def will_unload?(const_desc) + autoloaded?(desc) || + explicitly_unloadable_constants.include?(const_desc.to_constant_name) + end + + # Mark the provided constant name for unloading. This constant will be + # unloaded on each request, not just the next one. + def mark_for_unload(const_desc) + name = const_desc.to_constant_name + unless explicitly_unloadable_constants.include? name + explicitly_unloadable_constants << name + end + end + class LoadingModule # Old style environment.rb referenced this method directly. Please note, it doesn't # actualy *do* anything any more. @@ -300,6 +311,21 @@ protected end end + def remove_constant(const) + return false unless qualified_const_defined? const + + names = const.split('::') + if names.size == 1 || names.first.empty? # It's under Object + parent = Object + else + parent = (names[0..-2] * '::').constantize + end + + log "removing constant #{const}" + parent.send :remove_const, names.last + return true + end + def log_call(*args) arg_str = args.collect(&:inspect) * ', ' /in `([a-z_\?\!]+)'/ =~ caller(1).first |