Class: Petit::Router
- Inherits:
-
Object
- Object
- Petit::Router
- Defined in:
- lib/petit/router.rb
Class Method Summary collapse
-
.application(links = Petit.links) ⇒ Object
Generates a Rack::Builder object for URLs mapped redirects.
-
.server(port = 4200, server = 'webrick') ⇒ Object
Starts the petit routing, this should be used in development mode port - port the server needs to start on (default: 4200) server - the type of server (default: webrick) Returns nothing.
Class Method Details
.application(links = Petit.links) ⇒ Object
Generates a Rack::Builder object for URLs mapped redirects
+links+ a hash of links to redirect
Usage:
require “petit”
links = {
'/foo' => 'http://bar.com',
'/piyo' => 'http//fuga.com'
}
Petit::Router.application(links)
Returns Rack::Builder
22 23 24 25 26 27 28 29 30 |
# File 'lib/petit/router.rb', line 22 def application(links = Petit.links) Rack::Builder.new do links.each do |source,dest| map source do run Proc.new {|env| RackHelper.redirect_response(dest)} end end end end |
.server(port = 4200, server = 'webrick') ⇒ Object
Starts the petit routing, this should be used in development mode port - port the server needs to start on (default: 4200) server - the type of server (default: webrick) Returns nothing
37 38 39 |
# File 'lib/petit/router.rb', line 37 def server(port = 4200, server ='webrick') Rack::Server.new(:app => application, :Port => port, :server => server).start end |