Represents the applications middleware as a stack, allowing for easily removing middleware or finding places to insert new middleware.
Public Class methods
# File lib/roda/plugins/middleware_stack.rb 42 def initialize(app, middleware) 43 @app = app 44 @middleware = middleware 45 end
Public Instance methods
Return a StackPosition
representing the position after the middleware where the block returns true. Yields the middleware and any middleware arguments given, but not the middleware block. It the block never returns true, returns a StackPosition
that will insert new middleware at the end of the stack.
# File lib/roda/plugins/middleware_stack.rb 52 def after(&block) 53 handle(1, &block) 54 end
Return a StackPosition
representing the position before the middleware where the block returns true. Yields the middleware and any middleware arguments given, but not the middleware block. It the block never returns true, returns a StackPosition
that will insert new middleware at the end of the stack.
# File lib/roda/plugins/middleware_stack.rb 61 def before(&block) 62 handle(0, &block) 63 end
Removes any middleware where the block returns true. Yields the middleware and any middleware arguments given, but not the middleware block
# File lib/roda/plugins/middleware_stack.rb 67 def remove 68 @middleware.delete_if do |m, _| 69 yield(*m) 70 end 71 @app.send(:build_rack_app) 72 nil 73 end