class Roda::RodaPlugins::MiddlewareStack::Stack
removing middleware or finding places to insert new middleware.
Represents the applications middleware as a stack, allowing for easily
def after(&block)
It the block never returns true, returns a StackPosition that will insert
given, but not the middleware block.
the block returns true. Yields the middleware and any middleware arguments
Return a StackPosition representing the position after the middleware where
def after(&block) handle(1, &block) end
def before(&block)
It the block never returns true, returns a StackPosition that will insert
given, but not the middleware block.
the block returns true. Yields the middleware and any middleware arguments
Return a StackPosition representing the position before the middleware where
def before(&block) handle(0, &block) end
def handle(offset)
def handle(offset) @middleware.each_with_index do |(m, _), i| if yield(*m) return StackPosition.new(@app, @middleware, i+offset) end end StackPosition.new(@app, @middleware, @middleware.length) end
def initialize(app, middleware)
def initialize(app, middleware) @app = app @middleware = middleware end
def remove
Removes any middleware where the block returns true. Yields the middleware
def remove @middleware.delete_if do |m, _| yield(*m) end @app.send(:build_rack_app) nil end