From 7418a440967586851a182bbcd6d93dbba9497cdb Mon Sep 17 00:00:00 2001
From: Carl Lerche <me@carllerche.com>
Date: Fri, 17 Sep 2010 12:05:40 -0700
Subject: Add RouteSet#append

	Allows specifying blocks to the routeset that will get 	appended after the RouteSet is drawn.
---
 actionpack/lib/action_dispatch/routing/route_set.rb | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

(limited to 'actionpack/lib')

diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 835ba03784..7ac07fe426 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -217,27 +217,35 @@ module ActionDispatch
         self.valid_conditions.delete(:id)
         self.valid_conditions.push(:controller, :action)
 
+        @append = []
         @disable_clear_and_finalize = false
         clear!
       end
 
       def draw(&block)
         clear! unless @disable_clear_and_finalize
+        eval_block(block)
+        finalize! unless @disable_clear_and_finalize
+
+        nil
+      end
+
+      def append(&block)
+        @append << block
+      end
 
+      def eval_block(block)
         mapper = Mapper.new(self)
         if default_scope
           mapper.with_default_scope(default_scope, &block)
         else
           mapper.instance_exec(&block)
         end
-
-        finalize! unless @disable_clear_and_finalize
-
-        nil
       end
 
       def finalize!
         return if @finalized
+        @append.each { |blk| eval_block(blk) }
         @finalized = true
         @set.freeze
       end
-- 
cgit v1.2.3