Class: Wayfarer::Routing::Matchers::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/wayfarer/routing/matchers/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, route) ⇒ Path

Returns a new instance of Path.



12
13
14
15
16
17
# File 'lib/wayfarer/routing/matchers/path.rb', line 12

def initialize(path, route)
  @path = path
  @route = route
  @peeking = false
  @matcher = Mustermann.new(path, type: "sinatra") # TODO: Add type constant
end

Instance Attribute Details

#matcherObject (readonly)

Returns the value of attribute matcher.



7
8
9
# File 'lib/wayfarer/routing/matchers/path.rb', line 7

def matcher
  @matcher
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/wayfarer/routing/matchers/path.rb', line 7

def path
  @path
end

#peekingObject (readonly)

Returns the value of attribute peeking.



7
8
9
# File 'lib/wayfarer/routing/matchers/path.rb', line 7

def peeking
  @peeking
end

#routeObject (readonly)

Returns the value of attribute route.



7
8
9
# File 'lib/wayfarer/routing/matchers/path.rb', line 7

def route
  @route
end

Instance Method Details

#match(url) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/wayfarer/routing/matchers/path.rb', line 19

def match(url)
  # TODO: Ditch this and add a parameter to the path DSL#path
  #
  # If the route's branch contains other path matchers in child routes,
  # match the beginning of the path (peeking), instead of the whole path.
  route.accept(self)

  !!(if peeking
       matcher.peek(url.path)
     else
       matcher.match(url.path)
     end)
end

#params(url) ⇒ Object



33
34
35
36
37
# File 'lib/wayfarer/routing/matchers/path.rb', line 33

def params(url)
  return {} unless match(url)

  matcher.params(url.path) || {}
end

#visit(route) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/wayfarer/routing/matchers/path.rb', line 39

def visit(route)
  return true if route == self.route
  return true if route.is_a?(TargetRoute)

  return unless route.matcher.is_a?(self.class)

  @peeking = true
  false
end