Class: Wayfarer::Routing::Route

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/wayfarer/routing/route.rb

Direct Known Subclasses

RootRoute, TargetRoute

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

#custom, #host, #path, #query, #scheme, #suffix, #to, #url

Constructor Details

#initialize(matcher = CustomMatcher.new { children.any? }, path_offset = "/") ⇒ Route

Returns a new instance of Route.



15
16
17
18
19
# File 'lib/wayfarer/routing/route.rb', line 15

def initialize(matcher = CustomMatcher.new { children.any? }, path_offset = "/")
  @matcher = matcher
  @children = []
  @path_offset = path_offset
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



10
11
12
# File 'lib/wayfarer/routing/route.rb', line 10

def action
  @action
end

#childrenObject (readonly)

Returns the value of attribute children.



8
9
10
# File 'lib/wayfarer/routing/route.rb', line 8

def children
  @children
end

#matcherObject

Returns the value of attribute matcher.



10
11
12
# File 'lib/wayfarer/routing/route.rb', line 10

def matcher
  @matcher
end

#parentObject

Returns the value of attribute parent.



10
11
12
# File 'lib/wayfarer/routing/route.rb', line 10

def parent
  @parent
end

#path_offsetObject

Returns the value of attribute path_offset.



10
11
12
# File 'lib/wayfarer/routing/route.rb', line 10

def path_offset
  @path_offset
end

Instance Method Details

#accept(visitor) ⇒ Object

Accepts a visitor for in-order traversal.



34
35
36
37
38
# File 'lib/wayfarer/routing/route.rb', line 34

def accept(visitor)
  return unless visitor.visit(self)

  children.each { |child| child.accept(visitor) }
end

#invoke(url) ⇒ Object



29
30
31
# File 'lib/wayfarer/routing/route.rb', line 29

def invoke(url)
  PathFinder.result(self, url)
end

#match(url) ⇒ Object



21
22
23
# File 'lib/wayfarer/routing/route.rb', line 21

def match(url)
  matcher.match(url)
end

#matches?(url) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/wayfarer/routing/route.rb', line 25

def matches?(url)
  invoke(url).is_a?(Result::Match)
end