class Roda::RodaPlugins::Middleware::Forwarder

Forward instances are what is actually used as middleware.

Public Class Methods

new(mid, app) click to toggle source

Store the current middleware and the next middleware to call.

# File lib/roda/plugins/middleware.rb, line 40
def initialize(mid, app)
  @mid = mid.app
  @app = app
end

Public Instance Methods

call(env) click to toggle source

When calling the middleware, first call the current middleware. If this returns a result, return that result directly. Otherwise, pass handling of the request to the next middleware.

# File lib/roda/plugins/middleware.rb, line 48
def call(env)
  res = nil

  call_next = catch(:next) do
    res = @mid.call(env)
    false
  end

  if call_next
    @app.call(env)
  else
    res
  end
end