Class: Wayfarer::Routing::PathMatcher
- Inherits:
-
Object
- Object
- Wayfarer::Routing::PathMatcher
- Defined in:
- lib/wayfarer/routing/path_matcher.rb
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#peeking ⇒ Object
readonly
Returns the value of attribute peeking.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
-
#initialize(path, route) ⇒ PathMatcher
constructor
A new instance of PathMatcher.
- #match(url) ⇒ Object
- #params(url) ⇒ Object
- #visit(route) ⇒ Object
Constructor Details
#initialize(path, route) ⇒ PathMatcher
Returns a new instance of PathMatcher.
11 12 13 14 15 16 |
# File 'lib/wayfarer/routing/path_matcher.rb', line 11 def initialize(path, route) @path = path @route = route @peeking = false @matcher = Mustermann.new(path, type: "sinatra") end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
6 7 8 |
# File 'lib/wayfarer/routing/path_matcher.rb', line 6 def matcher @matcher end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/wayfarer/routing/path_matcher.rb', line 6 def path @path end |
#peeking ⇒ Object (readonly)
Returns the value of attribute peeking.
6 7 8 |
# File 'lib/wayfarer/routing/path_matcher.rb', line 6 def peeking @peeking end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
6 7 8 |
# File 'lib/wayfarer/routing/path_matcher.rb', line 6 def route @route end |
Instance Method Details
#match(url) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wayfarer/routing/path_matcher.rb', line 18 def match(url) route.accept(self) # If the route's branch contains other path matchers in child routes, # match the beginning of the path (peeking), instead of the whole path. !!(if peeking matcher.peek(url.path) else matcher.match(url.path) end) end |
#params(url) ⇒ Object
30 31 32 33 34 |
# File 'lib/wayfarer/routing/path_matcher.rb', line 30 def params(url) return {} unless match(url) matcher.params(url.path) || {} end |
#visit(route) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/wayfarer/routing/path_matcher.rb', line 36 def visit(route) return true if route == self.route return unless route.matcher.is_a?(self.class) @peeking = true false end |