Module: Doze::Router::AnchoredRouteSet
- Included in:
- Doze::Router, ClassMethods
- Defined in:
- lib/doze/router/anchored_route_set.rb
Instance Method Summary collapse
- #expand_route_template(name, vars) ⇒ Object
- #get_route(name, vars = {}, session = nil) ⇒ Object
- #partially_expand_route_template(name, vars) ⇒ Object
- #perform_routing_with_parent(parent_router, path, session, base_uri) ⇒ Object
-
#propagate_static_routes(uri) ⇒ Object
What this does: - Informs this instance of the fixed uri at which it’s known to be anchored - Uses this information to infer fixed uris for the target_route_set of any of our routes which are not parameterized? and which routes_uniquely_to_target?, and recursively tell these AnchoredRouteSets their fixed uris.
-
#route_template(name) ⇒ Object
Some utility functions based on this interface.
- #router_uri_prefix ⇒ Object
- #router_uri_prefix= ⇒ Object
-
#routes ⇒ Object
Key interface to implement here is #routes and #router_uri_prefix.
Instance Method Details
#expand_route_template(name, vars) ⇒ Object
23 24 25 |
# File 'lib/doze/router/anchored_route_set.rb', line 23 def (name, vars) route = routes[name] and route.(vars, router_uri_prefix) end |
#get_route(name, vars = {}, session = nil) ⇒ Object
31 32 33 |
# File 'lib/doze/router/anchored_route_set.rb', line 31 def get_route(name, vars={}, session=nil) route = routes[name] and route.call(self, vars, session) end |
#partially_expand_route_template(name, vars) ⇒ Object
27 28 29 |
# File 'lib/doze/router/anchored_route_set.rb', line 27 def (name, vars) route = routes[name] and route.(vars, router_uri_prefix) end |
#perform_routing_with_parent(parent_router, path, session, base_uri) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/doze/router/anchored_route_set.rb', line 35 def perform_routing_with_parent(parent_router, path, session, base_uri) for route in routes match, uri, trailing = route.match(path) next unless match base_uri_for_match = base_uri + uri result = route.call(parent_router, match, session, base_uri_for_match) or next return [result, base_uri_for_match, trailing] end nil end |
#propagate_static_routes(uri) ⇒ Object
What this does:
- Informs this instance of the fixed uri at which it's known to be anchored
- Uses this information to infer fixed uris for the target_route_set of any of
our routes which are not parameterized? and which routes_uniquely_to_target?,
and recursively tell these AnchoredRouteSets their fixed uris.
This is called on the root resource as part of application initialization, to ensure that statically-known information about routing paths is propagated as far as possible through the resource model, so that resource instances can know their uris without necessarily having been a part of the routing chain for the current request.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/doze/router/anchored_route_set.rb', line 57 def propagate_static_routes(uri) self.router_uri_prefix = uri routes.each do |route| next if route.parameterized? or !route.routes_uniquely_to_target? target = route.target_route_set if target route_uri = route.template(router_uri_prefix).to_s target.propagate_static_routes(route_uri) end end end |
#route_template(name) ⇒ Object
Some utility functions based on this interface
19 20 21 |
# File 'lib/doze/router/anchored_route_set.rb', line 19 def route_template(name) route = routes[name] and route.template(router_uri_prefix) end |
#router_uri_prefix ⇒ Object
9 10 11 |
# File 'lib/doze/router/anchored_route_set.rb', line 9 def router_uri_prefix raise NotImplementedException end |
#router_uri_prefix= ⇒ Object
13 14 15 |
# File 'lib/doze/router/anchored_route_set.rb', line 13 def router_uri_prefix= raise NotImplementedException end |
#routes ⇒ Object
Key interface to implement here is #routes and #router_uri_prefix
5 6 7 |
# File 'lib/doze/router/anchored_route_set.rb', line 5 def routes raise NotImplementedException end |