Class: Webmachine::Dispatcher::Route
- Inherits:
-
Object
- Object
- Webmachine::Dispatcher::Route
- Defined in:
- lib/webmachine/dispatcher/route.rb
Overview
Pairs URIs with Resource classes in the Webmachine::Dispatcher. To create routes, use #add_route.
Constant Summary
- MATCH_ALL =
When used in a path specification, will match all remaining segments
'*'.freeze
Instance Attribute Summary (collapse)
-
- (Class) resource
readonly
The resource this route will dispatch to, a subclass of Resource.
Instance Method Summary (collapse)
-
- (Object) apply(request)
Decorates the request with information about the dispatch route, including path bindings.
-
- (Route) initialize(path_spec, resource, bindings = {})
constructor
Creates a new Route that will associate a pattern to a Resource.
-
- (Boolean) match?(request)
Determines whether the given request matches this route and should be dispatched to the #resource.
Constructor Details
- (Route) initialize(path_spec, resource, bindings = {})
Creates a new Route that will associate a pattern to a Resource.
29 30 31 32 |
# File 'lib/webmachine/dispatcher/route.rb', line 29 def initialize(path_spec, resource, bindings={}) @path_spec, @resource, @bindings = path_spec, resource, bindings raise ArgumentError, t('not_resource_class', :class => resource.name) unless resource < Resource end |
Instance Attribute Details
- (Class) resource (readonly)
The resource this route will dispatch to, a subclass of Resource
11 12 13 |
# File 'lib/webmachine/dispatcher/route.rb', line 11 def resource @resource end |
Instance Method Details
- (Object) apply(request)
Decorates the request with information about the dispatch route, including path bindings.
44 45 46 47 48 49 50 |
# File 'lib/webmachine/dispatcher/route.rb', line 44 def apply(request) request.disp_path = request.uri.path.match(/^\/(.*)/)[1] request.path_info = @bindings.dup tokens = request.disp_path.split('/') depth, trailing = bind(tokens, request.path_info) request.path_tokens = trailing || [] end |
- (Boolean) match?(request)
Determines whether the given request matches this route and should be dispatched to the #resource.
36 37 38 39 |
# File 'lib/webmachine/dispatcher/route.rb', line 36 def match?(request) tokens = request.uri.path.match(/^\/(.*)/)[1].split('/') bind(tokens, {}) end |