class Roda::RodaPlugins::MiddlewareStack::Stack

  1. lib/roda/plugins/middleware_stack.rb
Superclass: Object

Represents the applications middleware as a stack, allowing for easily removing middleware or finding places to insert new middleware.

Methods

Public Class

  1. new

Public Instance

  1. after
  2. before
  3. remove

Public Class methods

new (app, middleware)
[show source]
   # File lib/roda/plugins/middleware_stack.rb
42 def initialize(app, middleware)
43   @app = app
44   @middleware = middleware
45 end

Public Instance methods

after (&block)

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.

[show source]
   # File lib/roda/plugins/middleware_stack.rb
52 def after(&block)
53   handle(1, &block)
54 end
before (&block)

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.

[show source]
   # File lib/roda/plugins/middleware_stack.rb
61 def before(&block)
62   handle(0, &block)
63 end
remove ()

Removes any middleware where the block returns true. Yields the middleware and any middleware arguments given, but not the middleware block

[show source]
   # 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