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/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

See Also:

Direct Known Subclasses

Root

Defined Under Namespace

Classes: FailedResponse, Response, Root, RootIgnoringTrailingDelimiters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, value) ⇒ Node

Returns a new instance of Node.



25
26
27
# File 'lib/usher/node.rb', line 25

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

Instance Attribute Details

#greedyObject (readonly)

Returns the value of attribute greedy.



22
23
24
# File 'lib/usher/node.rb', line 22

def greedy
  @greedy
end

#normalObject (readonly)

Returns the value of attribute normal.



22
23
24
# File 'lib/usher/node.rb', line 22

def normal
  @normal
end

#parentObject

Returns the value of attribute parent.



23
24
25
# File 'lib/usher/node.rb', line 23

def parent
  @parent
end

#requestObject (readonly)

Returns the value of attribute request.



22
23
24
# File 'lib/usher/node.rb', line 22

def request
  @request
end

#request_method_typeObject

Returns the value of attribute request_method_type.



23
24
25
# File 'lib/usher/node.rb', line 23

def request_method_type
  @request_method_type
end

#request_methodsObject

Returns the value of attribute request_methods.



23
24
25
# File 'lib/usher/node.rb', line 23

def request_methods
  @request_methods
end

#terminatesObject

Returns the value of attribute terminates.



23
24
25
# File 'lib/usher/node.rb', line 23

def terminates
  @terminates
end

#valueObject

Returns the value of attribute value.



23
24
25
# File 'lib/usher/node.rb', line 23

def value
  @value
end

Instance Method Details

#inspectObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/usher/node.rb', line 29

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