lib/action_dispatch/middleware/stack.rb in actionpack-3.0.0.beta4 vs lib/action_dispatch/middleware/stack.rb in actionpack-3.0.0.rc

- old
+ new

@@ -44,21 +44,20 @@ super(*args) block.call(self) if block_given? end def insert(index, *args, &block) - index = self.index(index) unless index.is_a?(Integer) + index = assert_index(index, :before) middleware = self.class::Middleware.new(*args, &block) super(index, middleware) end alias_method :insert_before, :insert def insert_after(index, *args, &block) - i = index.is_a?(Integer) ? index : self.index(index) - raise "No such middleware to insert after: #{index.inspect}" unless i - insert(i + 1, *args, &block) + index = assert_index(index, :after) + insert(index + 1, *args, &block) end def swap(target, *args, &block) insert_before(target, *args, &block) delete(target) @@ -68,16 +67,24 @@ middleware = self.class::Middleware.new(*args, &block) push(middleware) end def active - ActiveSupport::Deprecation.warn "All middlewares in the chaing are active since the laziness " << + ActiveSupport::Deprecation.warn "All middlewares in the chain are active since the laziness " << "was removed from the middleware stack", caller end def build(app = nil, &block) app ||= block raise "MiddlewareStack#build requires an app" unless app reverse.inject(app) { |a, e| e.build(a) } + end + + protected + + def assert_index(index, where) + i = index.is_a?(Integer) ? index : self.index(index) + raise "No such middleware to insert #{where}: #{index.inspect}" unless i + i end end end