diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-11-23 21:50:21 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-11-23 21:50:21 -0600 |
commit | 59dbae145b939ca733b7fc9ed0205b01c3d6799c (patch) | |
tree | a176a950c116d5b4b75a7b6fcac47d0f3ca6de37 /actionpack/lib | |
parent | 15ab3a98a1b6f9b829060ba974048b33466f6814 (diff) | |
download | rails-59dbae145b939ca733b7fc9ed0205b01c3d6799c.tar.gz rails-59dbae145b939ca733b7fc9ed0205b01c3d6799c.tar.bz2 rails-59dbae145b939ca733b7fc9ed0205b01c3d6799c.zip |
Privatize Routing.possible_controllers and fix brittle url helper
controller test loading.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/routing.rb | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb index b43b77fecb..9b977800b4 100644 --- a/actionpack/lib/action_dispatch/routing.rb +++ b/actionpack/lib/action_dispatch/routing.rb @@ -277,45 +277,23 @@ module ActionDispatch class << self def controller_constraints - Regexp.union(*possible_controllers.collect { |n| Regexp.escape(n) }) + @controller_constraints ||= Regexp.union(*possible_controllers.collect { |n| Regexp.escape(n) }) end def clear_controller_cache! - @possible_controllers = nil + @controller_constraints = nil end - # Returns an array of paths, cleaned of double-slashes and relative path references. - # * "\\\" and "//" become "\\" or "/". - # * "/foo/bar/../config" becomes "/foo/config". - # The returned array is sorted by length, descending. - def normalize_paths(paths) - # do the hokey-pokey of path normalization... - paths = paths.collect do |path| - path = path. - gsub("//", "/"). # replace double / chars with a single - gsub("\\\\", "\\"). # replace double \ chars with a single - gsub(%r{(.)[\\/]$}, '\1') # drop final / or \ if path ends with it - - # eliminate .. paths where possible - re = %r{[^/\\]+[/\\]\.\.[/\\]} - path.gsub!(re, "") while path.match(re) - path - end - - # start with longest path, first - paths = paths.uniq.sort_by { |path| - path.length } - end - - # Returns the array of controller names currently available to ActionController::Routing. - def possible_controllers - unless @possible_controllers - @possible_controllers = [] + private + # Returns the array of controller names currently available to ActionController::Routing. + def possible_controllers + possible_controllers = [] # Find any controller classes already in memory ActionController::Base.subclasses.each do |klass| controller_name = klass.underscore controller_name.gsub!(/_controller\Z/, '') - @possible_controllers << controller_name + possible_controllers << controller_name end # Find controllers in controllers/ directory @@ -328,15 +306,37 @@ module ActionDispatch controller_name = path[(load_path.length + 1)..-1] controller_name.gsub!(/_controller\.rb\Z/, '') - @possible_controllers << controller_name + possible_controllers << controller_name end end # remove duplicates - @possible_controllers.uniq! + possible_controllers.uniq! + + possible_controllers + end + + # Returns an array of paths, cleaned of double-slashes and relative path references. + # * "\\\" and "//" become "\\" or "/". + # * "/foo/bar/../config" becomes "/foo/config". + # The returned array is sorted by length, descending. + def normalize_paths(paths) + # do the hokey-pokey of path normalization... + paths = paths.collect do |path| + path = path. + gsub("//", "/"). # replace double / chars with a single + gsub("\\\\", "\\"). # replace double \ chars with a single + gsub(%r{(.)[\\/]$}, '\1') # drop final / or \ if path ends with it + + # eliminate .. paths where possible + re = %r{[^/\\]+[/\\]\.\.[/\\]} + path.gsub!(re, "") while path.match(re) + path + end + + # start with longest path, first + paths = paths.uniq.sort_by { |path| - path.length } end - @possible_controllers - end end end end |