W3cubDocs

/Padrino

Class: Padrino::Router

Inherits:
Object
  • Object

Overview

This class is an extended version of Rack::URLMap.

Padrino::Router like Rack::URLMap dispatches in such a way that the longest paths are tried first, since they are most specific.

Features:

  • Map a path to the specified App

  • Ignore server names (this solve issues with vhost and domain aliases)

  • Use hosts instead of server name for mappings (this help us with our vhost and domain aliases)

Examples:

routes = Padrino::Router.new do
  map(:path => "/", :to => PadrinoWeb, :host => "padrino.local")
  map(:path => "/", :to => Admin, :host => "admin.padrino.local")
end
run routes

routes = Padrino::Router.new do
  map(:path => "/", :to => PadrinoWeb, :host => /*.padrino.local/)
end
run routes

Instance Method Summary

Constructor Details

#initialize(*mapping, &block) ⇒ Router

Returns a new instance of Router

Instance Method Details

#call(env) ⇒ Object

The call handler setup to route a request given the mappings specified.

#map(options = {}) ⇒ Array

Map a route path and host to a specified application.

Examples:

map(:path => "/", :to => PadrinoWeb, :host => "padrino.local")

Parameters:

  • options (Hash) (defaults to: {}) — The options to map.

Options Hash (options):

  • :to (Sinatra::Application) — The class of the application to mount.
  • :path (String) — default: "/" — The path to map the specified application.
  • :host (String) — The host to map the specified application.

Returns:

  • (Array) — The sorted route mappings.

Raises:

  • (ArgumentError)

© 2010–2016 Padrino
Licensed under the MIT License.
http://www.rubydoc.info/github/padrino/padrino-framework/Padrino/Router