Every repository with this icon (
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.DS_Store | ||
| |
README.textile | ||
| |
TODO.textile | ||
| |
dev/ | ||
| |
lib/ | ||
| |
routing.gemspec | ||
| |
spec/ |
Routing
Framework-agnostic, pure Ruby, fast, 2-way URL routing
Synopsis
@router = Routing::Router.new
@router.map(:users, :get, "users", "action" => "index")
@router.map(:user, :get, "users/:id", "action" => "show")
@router.map(:create_user, :post, "users", "action" => "create")
@router.compile!
@router.generate(:users)
=> [:get, "users", {}]
@router.generate(:user, "id" => "27")
=> [:get, "users/27", {}]
@router.generate(:user, "id" => "27", "format" => "js")
=> [:get, "users/27", {"format" => "js"}]
@router.recognize(:get, "users/27")
{"action" => "show", "id" => "27"}
Audience
The Routing library attempts to separate the core routing implementation from higher-level web frameworks. We intend to use it mainly as an experiment in routing in general, but may use it as a component of a future framework.
Threadsaftey
Router#map and Router#compile! are not threadsafe; their invocation must be
externally synchronized in a multithreaded environment. Router#recognize and
Router#generate are threadsafe.
Performance
There are three major performance considerations: memory usage, recognition
speed, and generation speed.
We’ve minimized memory usage by using a only a small number of primitive objects
and freeing extra objects after route compilation.
Recognition performance is achieved by compiling all routes to a big if/else
switch with inline regular expression conditions and params hash literals. If
you have a few hundred routes, you should be able to recognize about
10,000 paths/second. If you have more like a dozen, you can expect to recognize
about 100,000/second.
Generation performance is also high due to the use of named routes, generation
code that minimizes the amount interpolation/concatenation at runtime, and a
hand-optimized inner loop. You should be able to generate on the order of
25,000 dynamic routes per second.








