Class: Webmachine::Dispatcher::Route
- Inherits:
-
Object
- Object
- Webmachine::Dispatcher::Route
- Defined in:
- lib/webmachine/dispatcher/route.rb
Overview
Constant Summary
- MATCH_ALL =
When used in a path specification, will match all remaining segments
'*'.freeze
Instance Attribute Summary (collapse)
-
- (Array<String|Symbol>) path_spec
readonly
The list of path segments used to define this route (see #initialize).
-
- (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.
33 34 35 36 |
# File 'lib/webmachine/dispatcher/route.rb', line 33 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
- (Array<String|Symbol>) path_spec (readonly)
The list of path segments
used to define this route (see #initialize).
15 16 17 |
# File 'lib/webmachine/dispatcher/route.rb', line 15 def path_spec @path_spec end |
- (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.
49 50 51 52 53 54 55 |
# File 'lib/webmachine/dispatcher/route.rb', line 49 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.
41 42 43 44 |
# File 'lib/webmachine/dispatcher/route.rb', line 41 def match?(request) tokens = request.uri.path.match(/^\/(.*)/)[1].split('/') bind(tokens, {}) end |