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/failed_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: FailedResponse, Response, Root, RootIgnoringTrailingDelimiters, Terminates
Instance Attribute Summary collapse
-
#default_terminates ⇒ Object
Returns the value of attribute default_terminates.
-
#greedy ⇒ Object
readonly
Returns the value of attribute greedy.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#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
readonly
Returns the value of attribute terminates.
-
#unique_terminating_routes ⇒ Object
readonly
Returns the value of attribute unique_terminating_routes.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #add_meta(obj) ⇒ Object
- #add_terminate(path) ⇒ Object
-
#initialize(parent, value) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #remove_terminate(path) ⇒ Object
Constructor Details
#initialize(parent, value) ⇒ Node
Returns a new instance of Node.
29 30 31 |
# File 'lib/usher/node.rb', line 29 def initialize(parent, value) @parent, @value = parent, value end |
Instance Attribute Details
#default_terminates ⇒ Object
Returns the value of attribute default_terminates.
27 28 29 |
# File 'lib/usher/node.rb', line 27 def default_terminates @default_terminates end |
#greedy ⇒ Object (readonly)
Returns the value of attribute greedy.
26 27 28 |
# File 'lib/usher/node.rb', line 26 def greedy @greedy end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
26 27 28 |
# File 'lib/usher/node.rb', line 26 def @meta end |
#normal ⇒ Object (readonly)
Returns the value of attribute normal.
26 27 28 |
# File 'lib/usher/node.rb', line 26 def normal @normal end |
#parent ⇒ Object
Returns the value of attribute parent.
27 28 29 |
# File 'lib/usher/node.rb', line 27 def parent @parent end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
26 27 28 |
# File 'lib/usher/node.rb', line 26 def request @request end |
#request_method_type ⇒ Object
Returns the value of attribute request_method_type.
27 28 29 |
# File 'lib/usher/node.rb', line 27 def request_method_type @request_method_type end |
#request_methods ⇒ Object
Returns the value of attribute request_methods.
27 28 29 |
# File 'lib/usher/node.rb', line 27 def request_methods @request_methods end |
#terminates ⇒ Object (readonly)
Returns the value of attribute terminates.
26 27 28 |
# File 'lib/usher/node.rb', line 26 def terminates @terminates end |
#unique_terminating_routes ⇒ Object (readonly)
Returns the value of attribute unique_terminating_routes.
26 27 28 |
# File 'lib/usher/node.rb', line 26 def unique_terminating_routes @unique_terminating_routes end |
#value ⇒ Object
Returns the value of attribute value.
27 28 29 |
# File 'lib/usher/node.rb', line 27 def value @value end |
Instance Method Details
#add_meta(obj) ⇒ Object
45 46 47 |
# File 'lib/usher/node.rb', line 45 def (obj) << obj end |
#add_terminate(path) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/usher/node.rb', line 49 def add_terminate(path) if path.route.when_proc create_terminate.choices << path else create_terminate.default = path end unique_terminating_routes << path.route end |
#inspect ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/usher/node.rb', line 33 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 |
#remove_terminate(path) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/usher/node.rb', line 58 def remove_terminate(path) if terminates terminates.choices.delete(path) terminates.default = nil if terminates.default == path end unique_terminating_routes.delete_if{|r| r == path.route} end |