1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Nicholas Seckar 2005-10-27 17:40:48 +00:00
parent a7aa26906c
commit 727162e7fd
2 changed files with 10 additions and 8 deletions

View file

@ -1,5 +1,7 @@
*SVN* *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 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] * Added Time#end_of_month to accompany Time#beginning_of_month #2514 [Jens-Christian Fischer]

View file

@ -188,15 +188,15 @@ class Module #:nodoc:
return Object::Controllers.const_get(class_id) return Object::Controllers.const_get(class_id)
end end
file_name = class_id.to_s.demodulize.underscore
begin begin
require_dependency(class_id.to_s.demodulize.underscore) require_dependency(file_name)
if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end raise NameError.new("uninitialized constant #{class_id}") unless Object.const_defined?(class_id)
rescue LoadError => e return Object.const_get(class_id)
begin rescue MissingSourceFile => e
rails_original_const_missing(class_id) # Convert the exception to a NameError only if the file we are looking for is the missing one.
rescue Exception raise unless e.path == "#{file_name}.rb"
raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e) raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e)
end
end end
end end
end end