README¶ ↑
Description¶ ↑
Rupta is a router library for web applications. The routes can be defined with URI Template. The usage is so simple. See the following examples.
Installation¶ ↑
$ sudo gem install iwamot-rupta --source http://gems.github.com
Examples¶ ↑
examples/routing.rb¶ ↑
routes = {'bookmark' => ['http://example.com/bookmarks/{bookmark_id}', 'http://example.com/bookmarks/{bookmark_id}.{format}'], 'static_path' => ['http://example.com/static_path'], 'search' => ['http://example.com/search']} require 'rupta/factory' router = Rupta::Factory.new.create # Rupta#detect returns the name of a detected route, # a matched URI template and extracted URI parameters p router.detect(route, 'http://example.com/bookmarks/123.atom') # => ["bookmark", # "http://example.com/bookmarks/{bookmark_id}.{format}", # {"bookmark_id"=>"123", "format"=>"atom"}] # if the uri is static, the extracted parameters is empty p router.detect(routes, 'http://example.com/static_path') # => ["static_path", "http://example.com/static_path", {}] # query strings are omitted p router.detect(routes, 'http://example.com/search?q=foo') # => ["search", "http://example.com/search", {}] # when no route is found, Rupta#detect returns nil p router.detect(routes, 'http://example.com/not_found') # => nil
examples/fixtures/routes.yml¶ ↑
bookmark: - http://example.com/bookmarks/{bookmark_id} - http://example.com/bookmarks/{bookmark_id}.{format} static_path: - http://example.com/static_path search: - http://example.com/search
examples/routing_with_yaml_file.rb¶ ↑
yaml_path = File.expand_path('fixtures/routes.yml', File.dirname(__FILE__)) # use Rupta::Yaml::Factory, if you define routes in a YAML file require 'rupta/yaml/factory' rupta = Rupta::Yaml::Factory.new.create p rupta.detect(yaml_path, 'http://example.com/bookmarks/123.atom') # => ["bookmark", # "http://example.com/bookmarks/{bookmark_id}.{format}", # {"bookmark_id"=>"123", "format"=>"atom"}]
Requirement¶ ↑
Rupta-0.9.2 was tested with Ruby 1.9.1.
Dependencies¶ ↑
* addressable-2.1.0
Copyright¶ ↑
Copyright © 2009 IWAMOTO Takashi. See LICENSE for details.