public
Description: Stackable dynamic tree based Rack router
Homepage: http://rdoc.info/projects/josh/rack-mount/
Clone URL: git://github.com/josh/rack-mount.git
name age message
file .gitignore Wed Oct 21 21:16:11 -0700 2009 add pkg/ to ignore [josh]
file LICENSE Tue Feb 17 12:23:12 -0800 2009 first commit [josh]
file README.rdoc Sun Jul 26 19:52:35 -0700 2009 new generate api for generating isolated condit... [josh]
file Rakefile Sun Nov 08 17:11:58 -0800 2009 switch to reginald parser [josh]
directory benchmark/ Sat Nov 07 12:26:05 -0800 2009 dismantle Const [josh]
file deps.rip Tue Oct 27 21:11:36 -0700 2009 remove multimap dep [josh]
directory lib/ Sun Nov 08 19:42:27 -0800 2009 remove implicit prefixing [josh]
file rack-mount.gemspec Sat Oct 31 20:18:13 -0700 2009 replace strexp gsub parsing hacks with rex/racc [josh]
directory test/ Sun Nov 08 19:42:27 -0800 2009 remove implicit prefixing [josh]
README.rdoc

Rack::Mount

A stackable dynamic tree based Rack router.

Rack::Mount supports Rack’s Cascade style of trying several routes until it finds one that is not a 404. This allows multiple routes to be nested or stacked on top of each other. Since the application endpoint can trigger the router to continue matching, middleware can be used to add arbitrary conditions to any route. This allows you to route based on other request attributes, session information, or even data dynamically pulled from a database.

Usage

Rack::Mount provides a plugin API to build custom DSLs on top of.

The API is extremely minimal and only 3 methods are exposed as the public API.

Rack::Mount::RouteSet#add_route:builder method for adding routes to the set
Rack::Mount::RouteSet#call:Rack compatible recognition and dispatching method
Rack::Mount::RouteSet#url:generates path from identifiers or significant keys

Example

  require 'rack/mount'
  Routes = Rack::Mount::RouteSet.new do |set|
    # add_route takes a rack application and conditions to match with
    # conditions may be strings or regexps
    # See Rack::Mount::RouteSet#add_route for more options.
    set.add_route FooApp, :method => 'get' :path => %{/foo}
  end

  # The route set itself is a simple rack app you mount
  run Routes