Class: Wurk::Web::Extension::Route
- Inherits:
-
Object
- Object
- Wurk::Web::Extension::Route
- Defined in:
- lib/wurk/web/extension.rb
Overview
Compiles a Sinatra-style path ("/locks/:digest") into a matcher that extracts Symbol-keyed route params. A trailing "*" matches the rest.
Constant Summary collapse
- NAMED =
%r{/([^/]*):([^./:$]+)}
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ Route
constructor
A new instance of Route.
-
#match(path) ⇒ Object
Returns a
{key => value}Hash of route params, or nil if no match.
Constructor Details
#initialize(path) ⇒ Route
Returns a new instance of Route.
68 69 70 71 72 |
# File 'lib/wurk/web/extension.rb', line 68 def initialize(path) @path = path.to_s @keys = [] @regex = compile(@path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
66 67 68 |
# File 'lib/wurk/web/extension.rb', line 66 def path @path end |
Instance Method Details
#match(path) ⇒ Object
Returns a {key => value} Hash of route params, or nil if no match.
75 76 77 78 79 80 |
# File 'lib/wurk/web/extension.rb', line 75 def match(path) m = @regex.match(path) return nil unless m @keys.each_with_index.to_h { |k, i| [k, m[i + 1] && CGI.unescape(m[i + 1])] } end |