Skip to content
This repository
Browse code

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

…erous, and mostly used for testing.
  • Loading branch information...
commit 2fead68b3192332eee27945ed95a94a64ca73f70 1 parent b4d44d3
authored May 07, 2008
27  actionpack/lib/action_controller/routing.rb
@@ -277,6 +277,9 @@ module Helpers
277 277
     end
278 278
 
279 279
     class << self
  280
+	  # Expects an array of controller names as the first argument.  
  281
+	  # Executes the passed block with only the named controllers named available.
  282
+	  # This method is used in internal Rails testing.
280 283
       def with_controllers(names)
281 284
         prior_controllers = @possible_controllers
282 285
         use_controllers! names
@@ -285,6 +288,10 @@ def with_controllers(names)
285 288
         use_controllers! prior_controllers
286 289
       end
287 290
 
  291
+	  # Returns an array of paths, cleaned of double-slashes and relative path references.
  292
+	  # * "\\\" and "//"  become "\\" or "/". 
  293
+	  # * "/foo/bar/../config" becomes "/foo/config".
  294
+	  # The returned array is sorted by length, descending.
288 295
       def normalize_paths(paths)
289 296
         # do the hokey-pokey of path normalization...
290 297
         paths = paths.collect do |path|
@@ -303,6 +310,7 @@ def normalize_paths(paths)
303 310
         paths = paths.uniq.sort_by { |path| - path.length }
304 311
       end
305 312
 
  313
+	  # Returns the array of controller names currently available to ActionController::Routing.
306 314
       def possible_controllers
307 315
         unless @possible_controllers
308 316
           @possible_controllers = []
@@ -327,10 +335,28 @@ def possible_controllers
327 335
         @possible_controllers
328 336
       end
329 337
 
  338
+	  # Replaces the internal list of controllers available to ActionController::Routing with the passed argument.
  339
+	  #   ActionController::Routing.use_controllers!([ "posts", "comments", "admin/comments" ])
330 340
       def use_controllers!(controller_names)
331 341
         @possible_controllers = controller_names
332 342
       end
333 343
 
  344
+	  # Returns a controller path for a new +controller+ based on a +previous+ controller path.
  345
+	  # Handles 4 scenarios:
  346
+	  #
  347
+	  # * stay in the previous controller:
  348
+	  #     controller_relative_to( nil, "groups/discussion" ) # => "groups/discussion"
  349
+	  #
  350
+	  # * stay in the previous namespace:
  351
+	  #     controller_relative_to( "posts", "groups/discussion" ) # => "groups/posts"
  352
+	  #
  353
+	  # * forced move to the root namespace:
  354
+	  #     controller_relative_to( "/posts", "groups/discussion" ) # => "posts"
  355
+	  #
  356
+	  # * previous namespace is root:
  357
+	  #     controller_relative_to( "posts", "anything_with_no_slashes" ) # =>"posts"
  358
+	  #
  359
+	  
334 360
       def controller_relative_to(controller, previous)
335 361
         if controller.nil?           then previous
336 362
         elsif controller[0] == ?/    then controller[1..-1]
@@ -344,6 +370,7 @@ def controller_relative_to(controller, previous)
344 370
     Routes = RouteSet.new
345 371
 
346 372
     ::Inflector.module_eval do
  373
+	  # Ensures that routes are reloaded when Rails inflections are updated.
347 374
       def inflections_with_route_reloading(&block)
348 375
         returning(inflections_without_route_reloading(&block)) {
349 376
           ActionController::Routing::Routes.reload! if block_given?

0 notes on commit 2fead68

Please sign in to comment.
Something went wrong with that request. Please try again.