Skip to content

Commit

Permalink
Check NameErrors and re-raise if they do not match the expected constant
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3636 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
seckar committed Feb 22, 2006
1 parent bb7408f commit de54db3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN* *SVN*


* During controller resolution, update the NameError suppression to check for the expected constant. [Nicholas Seckar]

* Update script.aculo.us to V1.5.3 [Thomas Fuchs] * Update script.aculo.us to V1.5.3 [Thomas Fuchs]


* Added various InPlaceEditor options, #3746, #3891, #3896, #3906 [Bill Burcham, ruairi, sl33p3r] * Added various InPlaceEditor options, #3746, #3891, #3896, #3906 [Bill Burcham, ruairi, sl33p3r]
Expand Down
10 changes: 7 additions & 3 deletions actionpack/lib/action_controller/routing.rb
Expand Up @@ -232,20 +232,24 @@ def traverse_to_controller(segments, start_at = 0)
mod_name = segment.camelize mod_name = segment.camelize
controller_name = "#{mod_name}Controller" controller_name = "#{mod_name}Controller"


suppress(NameError) do begin
controller = eval("mod::#{controller_name}", nil, __FILE__, __LINE__) controller = eval("mod::#{controller_name}", nil, __FILE__, __LINE__)
expected_name = "#{mod.name}::#{controller_name}" expected_name = "#{mod.name}::#{controller_name}"


# Detect the case when const_get returns an object from a parent namespace. # Detect the case when const_get returns an object from a parent namespace.
if controller.is_a?(Class) && controller.ancestors.include?(ActionController::Base) && (mod == Object || controller.name == expected_name) if controller.is_a?(Class) && controller.ancestors.include?(ActionController::Base) && (mod == Object || controller.name == expected_name)
return controller, (index - start_at) return controller, (index - start_at)
end end
rescue NameError => e
raise unless /^uninitialized constant #{controller_name}$/ =~ e.message
end end


mod = suppress(NameError) do begin
next_mod = eval("mod::#{mod_name}", nil, __FILE__, __LINE__) next_mod = eval("mod::#{mod_name}", nil, __FILE__, __LINE__)
# Check that we didn't get a module from a parent namespace # Check that we didn't get a module from a parent namespace
(mod == Object || next_mod.name == "#{mod.name}::#{mod_name}") ? next_mod : nil mod = (mod == Object || next_mod.name == "#{mod.name}::#{mod_name}") ? next_mod : nil
rescue NameError => e
raise unless /^uninitialized constant #{mod_name}$/ =~ e.message
end end


return nil unless mod return nil unless mod
Expand Down

0 comments on commit de54db3

Please sign in to comment.