Class: Signpost::Route::Simple
- Inherits:
-
Object
- Object
- Signpost::Route::Simple
- Defined in:
- lib/signpost/route/simple.rb
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Environment constraints.
-
#endpoint ⇒ Object
readonly
Rack-compatible endpoint.
-
#matcher ⇒ Object
readonly
Route matcher/expander.
-
#name ⇒ Object
readonly
Route name.
-
#params ⇒ Object
readonly
Specific route params.
Instance Method Summary collapse
-
#expand(data = {}) ⇒ Object
Generate a string from path pattern.
-
#match(path, env) ⇒ Object
Match path and return matched data or nil if path doesn’t match.
Instance Attribute Details
#constraints ⇒ Object (readonly)
Environment constraints
Returns: Array
30 31 32 |
# File 'lib/signpost/route/simple.rb', line 30 def constraints @constraints end |
#endpoint ⇒ Object (readonly)
Rack-compatible endpoint
Returns: Proc|Object
16 17 18 |
# File 'lib/signpost/route/simple.rb', line 16 def endpoint @endpoint end |
#matcher ⇒ Object (readonly)
Route matcher/expander
Returns: Mustermann
9 10 11 |
# File 'lib/signpost/route/simple.rb', line 9 def matcher @matcher end |
#name ⇒ Object (readonly)
Route name
Returns: Symbol
37 38 39 |
# File 'lib/signpost/route/simple.rb', line 37 def name @name end |
#params ⇒ Object (readonly)
Specific route params
Returns: Hash
23 24 25 |
# File 'lib/signpost/route/simple.rb', line 23 def params @params end |
Instance Method Details
#expand(data = {}) ⇒ Object
Generate a string from path pattern
Params:
-
data Hash key-values for expanding
Example:
route.({ id: 42 }) #=> '/users/42'
Returns: String
72 73 74 |
# File 'lib/signpost/route/simple.rb', line 72 def (data={}) matcher.(:append, data) end |
#match(path, env) ⇒ Object
Match path and return matched data or nil if path doesn’t match
Params:
-
path String uri path
Example:
route.match('/users/42') #=> { 'controller' => 'Users', 'action' => 'Show', 'id' => '42' }
route.match('/foo/bar') #=> nil
Returns: Hash|NilClass
52 53 54 55 56 57 58 |
# File 'lib/signpost/route/simple.rb', line 52 def match(path, env) return unless data = matcher.match(path) return unless constraints.all? { |c| c.call(env) } params.merge(Hash[data.names.zip(data.captures)]) end |