Class: Corrupt::Router
- Inherits:
-
Object
- Object
- Corrupt::Router
- Defined in:
- lib/corrupt/router.rb
Overview
Handles URL dispatching for the application. Routes are stored in a class variable, accessible by Router.routes.
Class Method Summary collapse
-
.dispatch(path) ⇒ Object
Dispatch an incoming request
path
to a controller and action. -
.routes ⇒ Object
Return the configured routes.
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Router
constructor
The Router is normally used like this: Corrupt::Router.new do |route| route.map ‘/path’, :controller => ‘Kickass’, :action => ‘take_names’ end.
-
#map(path, options = {}) ⇒ Object
Maps incoming URLs to a controller and action.
Constructor Details
Class Method Details
.dispatch(path) ⇒ Object
Dispatch an incoming request path
to a controller and action.
28 29 30 31 32 33 34 35 |
# File 'lib/corrupt/router.rb', line 28 def self.dispatch(path) response = routes[path] if response Corrupt::Controller.const_get(response[:controller]).new.send(response[:action]) else Exceptions.new.four_oh_four end end |
.routes ⇒ Object
Return the configured routes.
23 24 25 |
# File 'lib/corrupt/router.rb', line 23 def self.routes @@routes end |
Instance Method Details
#map(path, options = {}) ⇒ Object
Maps incoming URLs to a controller and action. TODO: Maybe change the routes storage to a hash like:
@@routes[path] # => options
18 19 20 |
# File 'lib/corrupt/router.rb', line 18 def map(path, = {}) @@routes[path] = end |