From ca54cc5df72a8bd7660d5be8333dcee2b6949257 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 4 Jan 2009 00:56:52 -0800 Subject: Sync 'rails/rails/master' --- .../lib/action_controller/middleware_stack.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/middleware_stack.rb b/actionpack/lib/action_controller/middleware_stack.rb index 74f28565c0..2bccba2ba1 100644 --- a/actionpack/lib/action_controller/middleware_stack.rb +++ b/actionpack/lib/action_controller/middleware_stack.rb @@ -1,6 +1,14 @@ module ActionController class MiddlewareStack < Array class Middleware + def self.new(klass, *args, &block) + if klass.is_a?(self) + klass + else + super + end + end + attr_reader :args, :block def initialize(klass, *args, &block) @@ -65,6 +73,19 @@ module ActionController block.call(self) if block_given? end + def insert(index, *objs) + index = self.index(index) unless index.is_a?(Integer) + objs = objs.map { |obj| Middleware.new(obj) } + super(index, *objs) + end + + alias_method :insert_before, :insert + + def insert_after(index, *objs) + index = self.index(index) unless index.is_a?(Integer) + insert(index + 1, *objs) + end + def use(*args, &block) middleware = Middleware.new(*args, &block) push(middleware) -- cgit v1.2.3