Skip to content
This repository
Browse code

reuse the route collection and formatter by clearing them

  • Loading branch information...
commit 59b9fe961d2195b35f3934dc6228a248897656e6 1 parent 4ffe667
Aaron Patterson authored September 08, 2011
16  actionpack/lib/action_dispatch/routing/route_set.rb
@@ -228,6 +228,13 @@ def initialize(request_class = ActionDispatch::Request)
228 228
         @append = []
229 229
         @prepend = []
230 230
         @disable_clear_and_finalize = false
  231
+
  232
+        @set    = Journey::Routes.new
  233
+        @router = Journey::Router.new(@set, {
  234
+          :parameters_key => PARAMETERS_KEY,
  235
+          :request_class  => request_class})
  236
+        @formatter = Journey::Formatter.new @set
  237
+
231 238
         clear!
232 239
       end
233 240
 
@@ -270,11 +277,8 @@ def clear!
270 277
         @finalized = false
271 278
         routes.clear
272 279
         named_routes.clear
273  
-        @set    = Journey::Routes.new
274  
-        @router = Journey::Router.new(@set, {
275  
-          :parameters_key => PARAMETERS_KEY,
276  
-          :request_class  => request_class})
277  
-        @formatter = Journey::Formatter.new @set
  280
+        set.clear
  281
+        formatter.clear
278 282
         @prepend.each { |blk| eval_block(blk) }
279 283
       end
280 284
 
@@ -343,7 +347,7 @@ def empty?
343 347
       def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true)
344 348
         raise ArgumentError, "Invalid route name: '#{name}'" unless name.blank? || name.to_s.match(/^[_a-z]\w*$/i)
345 349
         route = Route.new(self, app, conditions, requirements, defaults, name, anchor)
346  
-        @set.add_route(route.app, route.conditions, route.defaults, route.name)
  350
+        @set.add_route(app, route.conditions, defaults, name)
347 351
         named_routes[name] = route if name
348 352
         routes << route
349 353
         route

0 notes on commit 59b9fe9

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