From 4eec5f4fbb995ce665cb82367cc3965e74147b19 Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Wed, 14 Mar 2007 23:27:28 +0000 Subject: 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 --- .../lib/active_support/core_ext/module/introspection.rb | 14 ++++++++++++++ activesupport/lib/active_support/dependencies.rb | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') 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| -- cgit v1.2.3