Class: Usher::Node
- Inherits:
-
Object
- Object
- Usher::Node
- 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
Defined Under Namespace
Classes: Response, Root, RootIgnoringTrailingDelimiters
Instance Attribute Summary collapse
-
#greedy ⇒ Object
readonly
Returns the value of attribute greedy.
-
#normal ⇒ Object
readonly
Returns the value of attribute normal.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#request_method_type ⇒ Object
Returns the value of attribute request_method_type.
-
#request_methods ⇒ Object
Returns the value of attribute request_methods.
-
#terminates ⇒ Object
Returns the value of attribute terminates.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #depth ⇒ Object
-
#initialize(parent, value) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #root ⇒ Object
- #route_set ⇒ Object
- #terminates? ⇒ Boolean
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
#greedy ⇒ Object (readonly)
Returns the value of attribute greedy.
8 9 10 |
# File 'lib/usher/node.rb', line 8 def greedy @greedy end |
#normal ⇒ Object (readonly)
Returns the value of attribute normal.
8 9 10 |
# File 'lib/usher/node.rb', line 8 def normal @normal end |
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/usher/node.rb', line 9 def parent @parent end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
8 9 10 |
# File 'lib/usher/node.rb', line 8 def request @request end |
#request_method_type ⇒ Object
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_methods ⇒ Object
Returns the value of attribute request_methods.
9 10 11 |
# File 'lib/usher/node.rb', line 9 def request_methods @request_methods end |
#terminates ⇒ Object
Returns the value of attribute terminates.
9 10 11 |
# File 'lib/usher/node.rb', line 9 def terminates @terminates end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/usher/node.rb', line 9 def value @value end |
Instance Method Details
#ancestors ⇒ Object
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 |
#depth ⇒ Object
15 16 17 |
# File 'lib/usher/node.rb', line 15 def depth @depth ||= parent.is_a?(Node) ? parent.depth + 1 : 0 end |
#inspect ⇒ Object
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 |
#root ⇒ Object
35 36 37 |
# File 'lib/usher/node.rb', line 35 def root @root ||= ancestors.last end |
#route_set ⇒ Object
39 40 41 |
# File 'lib/usher/node.rb', line 39 def route_set @route_set ||= root.route_set end |
#terminates? ⇒ Boolean
19 20 21 |
# File 'lib/usher/node.rb', line 19 def terminates? @terminates && @terminates.route.recognizable? end |