aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-06-04 17:28:04 -0700
committerwycats <wycats@gmail.com>2010-06-04 20:11:06 -0700
commita6b39428431abeaa0251bbf4b6582e578f81783f (patch)
treea85e09146a4e046cc69485df35c6b5bcea0bef8e /activesupport/lib
parent16ee4b4d1b125bd3edb5c191d58c7afdf6d3232e (diff)
downloadrails-a6b39428431abeaa0251bbf4b6582e578f81783f.tar.gz
rails-a6b39428431abeaa0251bbf4b6582e578f81783f.tar.bz2
rails-a6b39428431abeaa0251bbf4b6582e578f81783f.zip
Optimize LookupContext
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/dependencies.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index e14e225596..e0d2b70306 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,28 @@ module ActiveSupport #:nodoc:
def remove_unloadable_constants!
autoloaded_constants.each { |const| remove_constant const }
autoloaded_constants.clear
+ references.each {|k,v| v.clear! }
explicitly_unloadable_constants.each { |const| remove_constant const }
end
+ class Reference
+ def initialize(constant, name)
+ @constant, @name = constant, name
+ end
+
+ def get
+ @constant ||= Inflector.constantize(@name)
+ end
+
+ def clear!
+ @constant = nil
+ end
+ end
+
+ def ref(name)
+ references[name] ||= Reference.new(Inflector.constantize(name), name)
+ end
+
# Determine if the given constant has been automatically loaded.
def autoloaded?(desc)
# No name => anonymous module.
@@ -572,6 +594,7 @@ module ActiveSupport #:nodoc:
log "removing constant #{const}"
parent.instance_eval { remove_const to_remove }
+
return true
end