diff options
Diffstat (limited to 'actionpack/lib/action_dispatch/routing.rb')
-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 |