Class: Usher::Interface::Rails3

Inherits:
Object
  • Object
show all
Defined in:
lib/usher/interface/rails3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRails3

Returns a new instance of Rails3.



7
8
9
# File 'lib/usher/interface/rails3.rb', line 7

def initialize
  @router = Usher.new(:request_methods => [:request_method, :host, :port, :scheme], :generator => Usher::Util::Generators::URL.new)
end

Instance Attribute Details

#routerObject (readonly)

Returns the value of attribute router.



5
6
7
# File 'lib/usher/interface/rails3.rb', line 5

def router
  @router
end

Instance Method Details

#add_route(app, conditions = {}, defaults = {}, name = nil) ⇒ Object

Builder method to add a route to the set

app

A valid Rack app to call if the conditions are met.

conditions

A hash of conditions to match against. Conditions may be expressed as strings or regexps to match against.

defaults

A hash of values that always gets merged in

name

Symbol identifier for the route used with named route generations



20
21
22
23
24
# File 'lib/usher/interface/rails3.rb', line 20

def add_route(app, conditions = {}, defaults = {}, name = nil)
  route = router.add_route(conditions.delete(:path_info), :conditions => conditions, :defaults => defaults)
  route.name(name) if name
  route.to(app)
end

#call(env) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/usher/interface/rails3.rb', line 26

def call(env)
  request = ::Rack::Request.new(env)
  response = router.recognize(request, request.path_info)
  if response
    response.destination.call(env)
  else
    ::Rack::Response.new("No route found", 404).finish
  end
end

#reset!Object



51
52
53
# File 'lib/usher/interface/rails3.rb', line 51

def reset!
  router.reset!
end

#url(env, *args) ⇒ Object

Generates a url from Rack env and identifiers or significant keys.

To generate a url by named route, pass the name in as a Symbol.

url(env, :dashboard) # => "/dashboard"

Additional parameters can be passed in as a hash

url(env, :people, :id => "1") # => "/people/1"

If no name route is given, it will fall back to a slower generation search.

url(env, :controller => "people", :action => "show", :id => "1")
  # => "/people/1"


48
49
# File 'lib/usher/interface/rails3.rb', line 48

def url(env, *args)
end