aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2007-03-14 23:27:28 +0000
committerNicholas Seckar <nseckar@gmail.com>2007-03-14 23:27:28 +0000
commit4eec5f4fbb995ce665cb82367cc3965e74147b19 (patch)
treeb44ff95dc30372057dc47699423bad0c35c0a4b0 /activesupport/lib
parentbbcfb9b625c4ed471fcf7c827b700ccb025e7dd9 (diff)
downloadrails-4eec5f4fbb995ce665cb82367cc3965e74147b19.tar.gz
rails-4eec5f4fbb995ce665cb82367cc3965e74147b19.tar.bz2
rails-4eec5f4fbb995ce665cb82367cc3965e74147b19.zip
Update Dependencies to ignore constants inherited from ancestors. Closes #6951.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6426 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/module/introspection.rb14
-rw-r--r--activesupport/lib/active_support/dependencies.rb6
2 files changed, 17 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/introspection.rb b/activesupport/lib/active_support/core_ext/module/introspection.rb
index 0cd0d1ff2c..36481927aa 100644
--- a/activesupport/lib/active_support/core_ext/module/introspection.rb
+++ b/activesupport/lib/active_support/core_ext/module/introspection.rb
@@ -18,4 +18,18 @@ class Module
parents << Object unless parents.include? Object
parents
end
+
+ # Return the constants that have been defined locally by this object and not
+ # in an ancestor. This method may miss some constants if their definition in
+ # the ancestor is identical to their definition in the receiver.
+ def local_constants
+ inherited = {}
+ ancestors.each do |anc|
+ next if anc == self
+ anc.constants.each { |const| inherited[const] = anc.const_get(const) }
+ end
+ constants.select do |const|
+ ! inherited.key?(const) || inherited[const].object_id != const_get(const).object_id
+ end
+ end
end
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 4880b70804..2f6ae284bf 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -318,13 +318,13 @@ module Dependencies #:nodoc:
watch_frames = descs.collect do |desc|
if desc.is_a? Module
mod_name = desc.name
- initial_constants = desc.constants
+ initial_constants = desc.local_constants
elsif desc.is_a?(String) || desc.is_a?(Symbol)
mod_name = desc.to_s
# Handle the case where the module has yet to be defined.
initial_constants = if qualified_const_defined?(mod_name)
- mod_name.constantize.constants
+ mod_name.constantize.local_constants
else
[]
end
@@ -349,7 +349,7 @@ module Dependencies #:nodoc:
mod = mod_name.constantize
next [] unless mod.is_a? Module
- new_constants = mod.constants - prior_constants
+ new_constants = mod.local_constants - prior_constants
# Make sure no other frames takes credit for these constants.
constant_watch_stack.each do |frame_name, constants|