Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Documented class methods on ActionController::Routing. These are dang…

…erous, and mostly used for testing.
  • Loading branch information...
commit 2fead68b3192332eee27945ed95a94a64ca73f70 1 parent b4d44d3
Austin Putman authored
Showing with 27 additions and 0 deletions.
  1. +27 −0 actionpack/lib/action_controller/routing.rb
27 actionpack/lib/action_controller/routing.rb
View
@@ -277,6 +277,9 @@ module Helpers
end
class << self
+ # Expects an array of controller names as the first argument.
+ # Executes the passed block with only the named controllers named available.
+ # This method is used in internal Rails testing.
def with_controllers(names)
prior_controllers = @possible_controllers
use_controllers! names
@@ -285,6 +288,10 @@ def with_controllers(names)
use_controllers! prior_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|
@@ -303,6 +310,7 @@ def normalize_paths(paths)
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 = []
@@ -327,10 +335,28 @@ def possible_controllers
@possible_controllers
end
+ # Replaces the internal list of controllers available to ActionController::Routing with the passed argument.
+ # ActionController::Routing.use_controllers!([ "posts", "comments", "admin/comments" ])
def use_controllers!(controller_names)
@possible_controllers = controller_names
end
+ # Returns a controller path for a new +controller+ based on a +previous+ controller path.
+ # Handles 4 scenarios:
+ #
+ # * stay in the previous controller:
+ # controller_relative_to( nil, "groups/discussion" ) # => "groups/discussion"
+ #
+ # * stay in the previous namespace:
+ # controller_relative_to( "posts", "groups/discussion" ) # => "groups/posts"
+ #
+ # * forced move to the root namespace:
+ # controller_relative_to( "/posts", "groups/discussion" ) # => "posts"
+ #
+ # * previous namespace is root:
+ # controller_relative_to( "posts", "anything_with_no_slashes" ) # =>"posts"
+ #
+
def controller_relative_to(controller, previous)
if controller.nil? then previous
elsif controller[0] == ?/ then controller[1..-1]
@@ -344,6 +370,7 @@ def controller_relative_to(controller, previous)
Routes = RouteSet.new
::Inflector.module_eval do
+ # Ensures that routes are reloaded when Rails inflections are updated.
def inflections_with_route_reloading(&block)
returning(inflections_without_route_reloading(&block)) {
ActionController::Routing::Routes.reload! if block_given?
Please sign in to comment.
Something went wrong with that request. Please try again.