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 ‘=> value` Hash of route params, or nil if no match.
Constructor Details
#initialize(path) ⇒ Route
Returns a new instance of Route.
63 64 65 66 67 |
# File 'lib/wurk/web/extension.rb', line 63 def initialize(path) @path = path.to_s @keys = [] @regex = compile(@path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
61 62 63 |
# File 'lib/wurk/web/extension.rb', line 61 def path @path end |
Instance Method Details
#match(path) ⇒ Object
Returns a ‘=> value` Hash of route params, or nil if no match.
70 71 72 73 74 75 |
# File 'lib/wurk/web/extension.rb', line 70 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 |