diff options
author | Xavier Noria <fxn@hashref.com> | 2010-06-07 15:44:57 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-06-07 15:44:57 +0200 |
commit | 9e065c6bc175621ad30a416c8c4345f95ce3c264 (patch) | |
tree | 505df4243727a00d1f030205f2e64afe0d098e5e /activesupport/lib/active_support/dependencies.rb | |
parent | 0dbc732995a526354fb1e3c732af5dacdb863dda (diff) | |
parent | 1a8f784a236058101c6e8b6387aefc96e86a1e54 (diff) | |
download | rails-9e065c6bc175621ad30a416c8c4345f95ce3c264.tar.gz rails-9e065c6bc175621ad30a416c8c4345f95ce3c264.tar.bz2 rails-9e065c6bc175621ad30a416c8c4345f95ce3c264.zip |
Merge remote branch 'rails/master'
Diffstat (limited to 'activesupport/lib/active_support/dependencies.rb')
-rw-r--r-- | activesupport/lib/active_support/dependencies.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index e14e225596..16c3bc1142 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -47,6 +47,9 @@ module ActiveSupport #:nodoc: mattr_accessor :autoloaded_constants self.autoloaded_constants = [] + mattr_accessor :references + self.references = {} + # 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 @@ -476,9 +479,37 @@ module ActiveSupport #:nodoc: def remove_unloadable_constants! autoloaded_constants.each { |const| remove_constant const } autoloaded_constants.clear + Reference.clear! explicitly_unloadable_constants.each { |const| remove_constant const } end + class Reference + @@constants = Hash.new { |h, k| h[k] = Inflector.constantize(k) } + + attr_reader :name + + def initialize(name) + @name = name.to_s + @@constants[@name] = name if name.respond_to?(:name) + end + + def get + @@constants[@name] + end + + def self.clear! + @@constants.clear + end + end + + def ref(name) + references[name] ||= Reference.new(name) + end + + def constantize(name) + ref(name).get + end + # Determine if the given constant has been automatically loaded. def autoloaded?(desc) # No name => anonymous module. @@ -572,6 +603,7 @@ module ActiveSupport #:nodoc: log "removing constant #{const}" parent.instance_eval { remove_const to_remove } + return true end |