Class: Usher::Node::Root

Inherits:
Usher::Node show all
Defined in:
lib/usher/node/root.rb

Direct Known Subclasses

RootIgnoringTrailingDelimiters

Instance Attribute Summary

Attributes inherited from Usher::Node

#greedy, #normal, #parent, #request, #request_method_type, #request_methods, #terminates, #value

Instance Method Summary collapse

Methods inherited from Usher::Node

#inspect

Constructor Details

#initialize(route_set, request_methods) ⇒ Root

Returns a new instance of Root.



5
6
7
8
# File 'lib/usher/node/root.rb', line 5

def initialize(route_set, request_methods)
  super(route_set, nil)
  self.request_methods = request_methods
end

Instance Method Details

#add(route) ⇒ Object



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

def add(route)
  route.paths.each { |path| set_path_with_destination(path) }
end

#delete(route) ⇒ Object



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

def delete(route)
  route.paths.each { |path| set_path_with_destination(path, nil) }
end

#lookup(request_object, path) ⇒ Object



29
30
31
# File 'lib/usher/node/root.rb', line 29

def lookup(request_object, path)
  find(request_object, path, route_set.splitter.split(path))
end

#route_setObject



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

def route_set
  parent
end

#unique_routes(node = self, routes = []) ⇒ Object



22
23
24
25
26
27
# File 'lib/usher/node/root.rb', line 22

def unique_routes(node = self, routes = [])
  routes << node.terminates.route if node.terminates
  [:normal, :greedy, :request].each { |type| node.send(type).values.each { |v| unique_routes(v, routes) } if node.send(type) }
  routes.uniq!
  routes
end