Discover just what rack can do (rather, what middleware you have installed)
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib/rack
spec
README.rdoc
Rakefile
VERSION.yml
rack-capabilities.gemspec

README.rdoc

Rack::Capabilities

Usage

class CuriousMiddleware
  def initialize(app)
    @app = app
  end

  def curious?
    true #and how!
  end

  def call(env)
    # who is before me?
    env['rack.capabilities'].before(self)
    # returns Rack::Middleware2

    # who is after me?
    env['rack.capabilities'].after(self)
    # returns Rack::Middleware4

    # can I go find Rack::Middleware1?
    env['rack.capabilities'].find(Rack::Middleware1)
    # returns Rack::Middleware1

    # or just find based on anything!
    env['rack.capabilities'].find{|mw| mw.respond_to?(:curious?)}
    # returns our friend, CuriousMiddleware

    # And presumably you'd
    # want to do stuff..
    # but thats up to you

    @app.call(env)
  end

end

use Rack::Capabilities
use Rack::Middleware1
use Rack::Middleware2
use Rack::CuriousMiddleware
use Rack::Middleware4
use Rack::Middleware5

Caveats and Limitations

Rack::Capabilities must be required (not autoloaded as it must monkey patch Rack::Builder). The rack.capabilities environment variable is only available at call time.