Module: Doze::Router
- Includes:
- AnchoredRouteSet
- Defined in:
- lib/doze/router.rb
Overview
A Doze::Router is a Doze::AnchoredRouteSet which routes with itself as the parent Router. Including it also extends the class with Doze::AnchoredRouteSet, and the instances delegates its routes to the class.
Defined Under Namespace
Modules: AnchoredRouteSet, ClassMethods Classes: Route, RouteSet
Class Method Summary collapse
Instance Method Summary collapse
-
#add_route(*p, &b) ⇒ Object
Add an instance-specific route.
-
#authorize_routing(session) ⇒ Object
called upon by the framework return false to blanket deny authorization to all methods on all routed subresources.
-
#perform_routing(path, session, base_uri) ⇒ Object
The main method of the Router interface.
-
#router_uri_prefix ⇒ Object
If this particular router instance has a uri prefix associated with it.
-
#router_uri_prefix=(uri_prefix) ⇒ Object
Used primarily by propagate_static_routes.
-
#routes ⇒ Object
The default Router implementation can run against any RouteSet returned here.
Methods included from AnchoredRouteSet
#expand_route_template, #get_route, #partially_expand_route_template, #perform_routing_with_parent, #propagate_static_routes, #route_template
Class Method Details
.included(mod) ⇒ Object
9 10 11 |
# File 'lib/doze/router.rb', line 9 def self.included(mod) mod.extend(ClassMethods) if mod.is_a?(Class) # if you include this in another module, its self.included should call this one end |
Instance Method Details
#add_route(*p, &b) ⇒ Object
Add an instance-specific route. This dups the default route-set
46 47 48 49 |
# File 'lib/doze/router.rb', line 46 def add_route(*p, &b) @routes ||= routes.dup @routes.route(*p, &b) end |
#authorize_routing(session) ⇒ Object
called upon by the framework return false to blanket deny authorization to all methods on all routed subresources
71 72 73 |
# File 'lib/doze/router.rb', line 71 def (session) true end |
#perform_routing(path, session, base_uri) ⇒ Object
The main method of the Router interface.
You can override this if you like, but a flexible default implementation is provided which can be configured with the ‘route’ class method.
args:
path - the path to match.
may be a suffix of the actual request path, if this router has been
delegated to by a higher-level router)
method - symbol for the http method being routed for this path
session - session from the request - see Application.config[:session_from_rack_env]
base_uri - the base uri at which the routing is taking place
should return either:
nil if no route matched / subresource not found, or
[route_to, base_uri_for_match, trailing] where
route_to - Resource or Router to route the request to
base_uri_for_match - base uri for the resource or router which we matched
trailing - any trailing bits of path following from base_uri_for_match to be passed onto the next router
34 35 36 |
# File 'lib/doze/router.rb', line 34 def perform_routing(path, session, base_uri) perform_routing_with_parent(self, path, session, base_uri) end |
#router_uri_prefix ⇒ Object
If this particular router instance has a uri prefix associated with it. Will use a resource’s URI method where available, for the common case where the router is also a resource
53 54 55 56 57 58 |
# File 'lib/doze/router.rb', line 53 def router_uri_prefix @router_uri_prefix ||= begin u = respond_to?(:uri) ? uri : nil u && u.chomp('/') end end |
#router_uri_prefix=(uri_prefix) ⇒ Object
Used primarily by propagate_static_routes. As a (desired) side-effect, will also set the uri using #uri= where this router is also a resource.
62 63 64 65 66 67 |
# File 'lib/doze/router.rb', line 62 def router_uri_prefix=(uri_prefix) if respond_to?(:uri=) self.uri = (uri_prefix.empty? ? '/' : uri_prefix) end @router_uri_prefix = uri_prefix end |
#routes ⇒ Object
The default Router implementation can run against any RouteSet returned here. By default routes returns a RouteSet defined at the class level using the class-method routing helpers, but you can override this if you want to use some instance-specific RouteSet
41 42 43 |
# File 'lib/doze/router.rb', line 41 def routes @routes || self.class.routes end |