Class: Wayfarer::Routing::PathFinder

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ PathFinder

Returns a new instance of PathFinder.



19
20
21
22
23
24
# File 'lib/wayfarer/routing/path_finder.rb', line 19

def initialize(url)
  @url = url
  @path = []
  @action = nil
  @params = {}
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



14
15
16
# File 'lib/wayfarer/routing/path_finder.rb', line 14

def action
  @action
end

#paramsObject (readonly)

Returns the value of attribute params.



14
15
16
# File 'lib/wayfarer/routing/path_finder.rb', line 14

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/wayfarer/routing/path_finder.rb', line 14

def path
  @path
end

#urlObject (readonly)

Returns the value of attribute url.



14
15
16
# File 'lib/wayfarer/routing/path_finder.rb', line 14

def url
  @url
end

Class Method Details

.result(route, url) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/wayfarer/routing/path_finder.rb', line 6

def self.result(route, url)
  finder = new(url)
  route.accept(finder)
  return Result::Mismatch.new if finder.path.none?

  Result::Match.new(finder.action, finder.params)
end

Instance Method Details

#visit(route) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/wayfarer/routing/path_finder.rb', line 26

def visit(route)
  return false if path.any?
  return false unless route.match(url)

  follow(route) if route.children.none?
  true
end