Project

middleware

0.46
Repository is archived
No release in over 3 years
Low commit activity in last 3 years
There's a lot of open issues
Generalized implementation of the middleware abstraction for Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 2.1.0
~> 2.8.0
~> 2.8.0
~> 0.7.5
 Project Readme

Middleware

Build Status

This is a generalized library for using middleware patterns within your Ruby projects.

To get started, the best place to look is the user guide.

Installation

This project is distributed as a RubyGem:

$ gem install middleware

Usage

Once you create a basic middleware, you can use the builder to have a nice DSL to build middleware stacks. Calling the middleware is simple, as well.

# Basic middleware that just prints the inbound and
# outbound steps.
class Trace
  def initialize(app, value)
    @app   = app
    @value = value
  end

  def call(env)
    puts "--> #{@value}"
    @app.call(env)
    puts "<-- #{@value}"
  end
end

# Build the actual middleware stack which runs a sequence
# of slightly different versions of our middleware.
stack = Middleware::Builder.new do
  use Trace, "A"
  use Trace, "B"
  use Trace, "C"
end

# Run it!
stack.call(nil)

And the output:

--> A
--> B
--> C
<-- C
<-- B
<-- A

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request