Class: Usher::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/usher/node.rb,
lib/usher/node/root.rb,
lib/usher/node/response.rb,
lib/usher/node/root_ignoring_trailing_delimiters.rb

Direct Known Subclasses

Root

Defined Under Namespace

Classes: Response, Root, RootIgnoringTrailingDelimiters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, value) ⇒ Node

Returns a new instance of Node.



11
12
13
# File 'lib/usher/node.rb', line 11

def initialize(parent, value)
  @parent, @value = parent, value
end

Instance Attribute Details

#greedyObject (readonly)

Returns the value of attribute greedy.



8
9
10
# File 'lib/usher/node.rb', line 8

def greedy
  @greedy
end

#normalObject (readonly)

Returns the value of attribute normal.



8
9
10
# File 'lib/usher/node.rb', line 8

def normal
  @normal
end

#parentObject

Returns the value of attribute parent.



9
10
11
# File 'lib/usher/node.rb', line 9

def parent
  @parent
end

#requestObject (readonly)

Returns the value of attribute request.



8
9
10
# File 'lib/usher/node.rb', line 8

def request
  @request
end

#request_method_typeObject

Returns the value of attribute request_method_type.



9
10
11
# File 'lib/usher/node.rb', line 9

def request_method_type
  @request_method_type
end

#request_methodsObject

Returns the value of attribute request_methods.



9
10
11
# File 'lib/usher/node.rb', line 9

def request_methods
  @request_methods
end

#terminatesObject

Returns the value of attribute terminates.



9
10
11
# File 'lib/usher/node.rb', line 9

def terminates
  @terminates
end

#valueObject

Returns the value of attribute value.



9
10
11
# File 'lib/usher/node.rb', line 9

def value
  @value
end

Instance Method Details

#ancestorsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/usher/node.rb', line 23

def ancestors
  unless @ancestors
    @ancestors = []
    node = self
    while (node.respond_to?(:parent))
      @ancestors << node
      node = node.parent
    end
  end
  @ancestors
end

#depthObject



15
16
17
# File 'lib/usher/node.rb', line 15

def depth
  @depth ||= parent.is_a?(Node) ? parent.depth + 1 : 0
end

#inspectObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/usher/node.rb', line 43

def inspect
  out = ''
  out << " " * depth
  out << "#{terminates? ? '* ' : ''}#{depth}: #{value.inspect}\n"
  [:normal, :greedy, :request].each do |node_type|
    send(node_type).each do |k,v|
      out << (" " * (depth + 1)) << "#{node_type.to_s[0].chr} #{k.inspect} ==> \n" << v.inspect
    end if send(node_type)
  end
  out
end

#rootObject



35
36
37
# File 'lib/usher/node.rb', line 35

def root
  @root ||= ancestors.last
end

#route_setObject



39
40
41
# File 'lib/usher/node.rb', line 39

def route_set
  @route_set ||= root.route_set
end

#terminates?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/usher/node.rb', line 19

def terminates?
  @terminates && @terminates.route.recognizable?
end