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
Overview
The node class used to walk the tree looking for a matching route. The node has three different things that it looks for. ## Normal The normal hash is used to normally find matching parts. As well, the reserved key, ‘nil` is used to denote a variable match. ## Greedy The greedy hash is used when you want to match on the entire path. This match can trancend delimiters (unlike the normal match) and match as much of the path as needed. ## Request The request hash is used to find request method restrictions after the entire path has been consumed.
Once the node finishes looking for matches, it looks for a ‘terminates` on the node that is usable. If it finds one, it wraps it into a Response and returns that. All actual matching though should normally be done off of Root#lookup
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
-
#initialize(parent, value) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
Constructor Details
#initialize(parent, value) ⇒ Node
Returns a new instance of Node.
24 25 26 |
# File 'lib/usher/node.rb', line 24 def initialize(parent, value) @parent, @value = parent, value end |
Instance Attribute Details
#greedy ⇒ Object (readonly)
Returns the value of attribute greedy.
21 22 23 |
# File 'lib/usher/node.rb', line 21 def greedy @greedy end |
#normal ⇒ Object (readonly)
Returns the value of attribute normal.
21 22 23 |
# File 'lib/usher/node.rb', line 21 def normal @normal end |
#parent ⇒ Object
Returns the value of attribute parent.
22 23 24 |
# File 'lib/usher/node.rb', line 22 def parent @parent end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
21 22 23 |
# File 'lib/usher/node.rb', line 21 def request @request end |
#request_method_type ⇒ Object
Returns the value of attribute request_method_type.
22 23 24 |
# File 'lib/usher/node.rb', line 22 def request_method_type @request_method_type end |
#request_methods ⇒ Object
Returns the value of attribute request_methods.
22 23 24 |
# File 'lib/usher/node.rb', line 22 def request_methods @request_methods end |
#terminates ⇒ Object
Returns the value of attribute terminates.
22 23 24 |
# File 'lib/usher/node.rb', line 22 def terminates @terminates end |
#value ⇒ Object
Returns the value of attribute value.
22 23 24 |
# File 'lib/usher/node.rb', line 22 def value @value end |
Instance Method Details
#inspect ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/usher/node.rb', line 28 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 |