Skip to content

Commit

Permalink
When loading classes using const_missing, raise a NameError if and on…
Browse files Browse the repository at this point in the history
…ly 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
  • Loading branch information
seckar committed Oct 27, 2005
1 parent a7aa269 commit 727162e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions 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]
Expand Down
16 changes: 8 additions & 8 deletions activesupport/lib/active_support/dependencies.rb
Expand Up @@ -188,15 +188,15 @@ def const_missing(class_id)
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
Expand Down

0 comments on commit 727162e

Please sign in to comment.