资源说明:Routes library for ruby
= Routes UPDATE: Note that this was a part time project that it's now discontinued, as using a rak middleware would probably be a better solution. A routes library for ruby USAGE: Routes::Building.draw do map '/posts', :controller => 'posts', :action => 'index' map '/posts/:id', :controller => 'posts' map '/controller/:action', {} map '/:controller/:action/:id', {} map '/cool', lambda { |path| "This is #{path}" } map /.*/, :action => 'anything' end Routes::Recognition.new('/posts').recognize # => { :controller => 'posts', :action => 'index' } Routes::Recognition.new('/posts/1').recognize # => { :controller => 'posts', :id => '1' } Routes::Recognition.new('/controller/new').recognize # => { :action => 'new' } Routes::Recognition.new('/posts/show/1').recognize # => { :controller => 'posts', :action => 'show', :id => '1' } Routes::Recognition.new('/something').recognize # => { :action => 'anything' } Routes::Recognition.new('/cool').recognize.call('/cool') # => "This is /cool" Note that the library will not execute lambdas itself, so it's your responsibility to test the result returned. This allow more flexibility in my opinion because you can pass additional parameters to it like the env object. CONTRIBUTIONS I'm open to contributions and suggestions. Drop me an email at info@oscardelben.com
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。