aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2005-10-27 17:40:48 +0000
committerNicholas Seckar <nseckar@gmail.com>2005-10-27 17:40:48 +0000
commit727162e7fd56d4d853c755521eb52d42bd70908f (patch)
tree7dc5a226966f644341029008d235e3dc9f8b448b
parenta7aa26906c31ad5ca3069e390085c1089c24311c (diff)
downloadrails-727162e7fd56d4d853c755521eb52d42bd70908f.tar.gz
rails-727162e7fd56d4d853c755521eb52d42bd70908f.tar.bz2
rails-727162e7fd56d4d853c755521eb52d42bd70908f.zip
When loading classes using const_missing, raise a NameError if and only if the file we tried to load was not present.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2771 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/dependencies.rb16
2 files changed, 10 insertions, 8 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index a26598ffc2..523de67741 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* When loading classes using const_missing, raise a NameError if and only if the file we tried to load was not present. [Nicholas Seckar]
+
* Added petabytes and exebytes to numeric extensions #2397 [timct@mac.com]
* Added Time#end_of_month to accompany Time#beginning_of_month #2514 [Jens-Christian Fischer]
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 87883542a8..152db5b189 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -188,15 +188,15 @@ class Module #:nodoc:
return Object::Controllers.const_get(class_id)
end
+ file_name = class_id.to_s.demodulize.underscore
begin
- require_dependency(class_id.to_s.demodulize.underscore)
- if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end
- rescue LoadError => e
- begin
- rails_original_const_missing(class_id)
- rescue Exception
- raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e)
- end
+ require_dependency(file_name)
+ raise NameError.new("uninitialized constant #{class_id}") unless Object.const_defined?(class_id)
+ return Object.const_get(class_id)
+ rescue MissingSourceFile => e
+ # Convert the exception to a NameError only if the file we are looking for is the missing one.
+ raise unless e.path == "#{file_name}.rb"
+ raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e)
end
end
end