From 52d4166947d94a3648f1531239491f51cd73f2de Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Sat, 5 Aug 2006 22:52:15 +0000 Subject: Raise fully qualified names upon name errors. Closes #5533. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4681 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_support/core_ext/name_error.rb | 7 ++++++- activesupport/lib/active_support/dependencies.rb | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/name_error.rb b/activesupport/lib/active_support/core_ext/name_error.rb index 42b89d3d28..2b617b0083 100644 --- a/activesupport/lib/active_support/core_ext/name_error.rb +++ b/activesupport/lib/active_support/core_ext/name_error.rb @@ -9,7 +9,12 @@ class NameError < StandardError # Was this exception raised because the given name was missing? def missing_name?(name) - missing_name == name.to_s + if name.is_a? Symbol + last_name = (missing_name || '').split('::').last + last_name == name.to_s + else + missing_name == name.to_s + end end end \ No newline at end of file diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 17ca446650..a58989173e 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -69,6 +69,11 @@ module Dependencies #:nodoc: history << file_name end + # Return the a constant path for the provided parent and constant name + def constant_path_for(mod, name) + ([Object, Kernel].include? mod) ? name.to_s : "#{mod}::#{name}" + end + class LoadingModule # Old style environment.rb referenced this method directly. Please note, it doesn't # actualy *do* anything any more. @@ -120,7 +125,8 @@ class Module #:nodoc: end end - raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e) + qualified_name = Dependencies.constant_path_for self, class_id + raise NameError.new("uninitialized constant #{qualified_name}").copy_blame!(e) end end end @@ -130,7 +136,15 @@ class Class if [Object, Kernel].include?(self) || parent == self super else - parent.send :const_missing, class_id + begin + parent.send :const_missing, class_id + rescue NameError => e + # Make sure that the name we are missing is the one that caused the error + parent_qualified_name = Dependencies.constant_path_for parent, class_id + raise unless e.missing_name? parent_qualified_name + qualified_name = Dependencies.constant_path_for self, class_id + raise NameError.new("uninitialized constant #{qualified_name}").copy_blame!(e) + end end end end -- cgit v1.2.3