Class: Middleware::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/middleware/runner.rb

Overview

This is a basic runner for middleware stacks. This runner does the default expected behavior of running the middleware stacks in order, then reversing the order.

Constant Summary collapse

EMPTY_MIDDLEWARE =

A middleware which does nothing

lambda { |env| }

Instance Method Summary collapse

Constructor Details

#initialize(stack) ⇒ Runner

Build a new middleware runner with the given middleware stack.

Note: This class usually doesn't need to be used directly. Instead, take a look at using the Builder class, which is a much friendlier way to build up a middleware stack.

Parameters:

  • stack (Array)

    An array of the middleware to run.



17
18
19
20
21
# File 'lib/middleware/runner.rb', line 17

def initialize(stack)
  # We need to take the stack of middleware and initialize them
  # all so they call the proper next middleware.
  @kickoff = build_call_chain(stack)
end

Instance Method Details

#call(env) ⇒ Object

Run the middleware stack with the given state bag.

Parameters:

  • env (Object)

    The state to pass into as the initial environment data. This is usual a hash of some sort.



27
28
29
30
31
32
# File 'lib/middleware/runner.rb', line 27

def call(env)
  # We just call the kickoff middleware, which is responsible
  # for properly calling the next middleware, and so on and so
  # forth.
  @kickoff.call(env)
end