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

#default_terminates, #greedy, #meta, #normal, #parent, #request, #request_method_type, #request_methods, #terminates, #unique_terminating_routes, #value

Instance Method Summary collapse

Methods inherited from Usher::Node

#add_terminate, #inspect, #remove_terminate

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)
  get_nodes_for_route(route) {|p, n| n.add_terminate(p)}
end

#add_meta(route, obj) ⇒ Object



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

def add_meta(route, obj)
  get_nodes_for_route(route) {|p, n| n.add_meta(obj)}
end

#delete(route) ⇒ Object



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

def delete(route)
  get_nodes_for_route(route) {|p, n| n.remove_terminate(p)}
end

#lookup(request_object, path) ⇒ Object



33
34
35
# File 'lib/usher/node/root.rb', line 33

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



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

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