aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/dependencies.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/dependencies.rb')
-rw-r--r--activesupport/lib/active_support/dependencies.rb32
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