Class: HttpRouter::Node
- Inherits:
-
Object
show all
- Defined in:
- lib/http_router/node.rb,
lib/http_router/node/glob.rb,
lib/http_router/node/host.rb,
lib/http_router/node/path.rb,
lib/http_router/node/root.rb,
lib/http_router/node/regex.rb,
lib/http_router/node/lookup.rb,
lib/http_router/node/scheme.rb,
lib/http_router/node/variable.rb,
lib/http_router/node/free_regex.rb,
lib/http_router/node/glob_regex.rb,
lib/http_router/node/user_agent.rb,
lib/http_router/node/request_method.rb,
lib/http_router/node/spanning_regex.rb,
lib/http_router/node/abstract_request_node.rb
Defined Under Namespace
Classes: AbstractRequestNode, FreeRegex, Glob, GlobRegex, Host, Lookup, Path, Regex, RequestMethod, Root, Scheme, SpanningRegex, UserAgent, Variable
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(router, parent, matchers = []) ⇒ Node
Returns a new instance of Node.
21
22
23
|
# File 'lib/http_router/node.rb', line 21
def initialize(router, parent, matchers = [])
@router, @parent, @matchers = router, parent, matchers
end
|
Instance Attribute Details
#router ⇒ Object
Returns the value of attribute router.
19
20
21
|
# File 'lib/http_router/node.rb', line 19
def router
@router
end
|
Instance Method Details
#add_destination(route, path, param_names = []) ⇒ Object
65
66
67
|
# File 'lib/http_router/node.rb', line 65
def add_destination(route, path, param_names = [])
add(Path.new(@router, self, route, path, param_names))
end
|
#add_free_match(regexp) ⇒ Object
61
62
63
|
# File 'lib/http_router/node.rb', line 61
def add_free_match(regexp)
add(FreeRegex.new(@router, self, regexp))
end
|
#add_glob ⇒ Object
29
30
31
|
# File 'lib/http_router/node.rb', line 29
def add_glob
add(Glob.new(@router, self))
end
|
#add_glob_regexp(matcher) ⇒ Object
33
34
35
|
# File 'lib/http_router/node.rb', line 33
def add_glob_regexp(matcher)
add(GlobRegex.new(@router, self, matcher))
end
|
#add_host(hosts) ⇒ Object
37
38
39
|
# File 'lib/http_router/node.rb', line 37
def add_host(hosts)
add(Host.new(@router, self, hosts))
end
|
#add_lookup(part) ⇒ Object
69
70
71
|
# File 'lib/http_router/node.rb', line 69
def add_lookup(part)
add(Lookup.new(@router, self)).add(part)
end
|
#add_match(regexp, matching_indicies = [0], splitting_indicies = nil) ⇒ Object
53
54
55
|
# File 'lib/http_router/node.rb', line 53
def add_match(regexp, matching_indicies = [0], splitting_indicies = nil)
add(Regex.new(@router, self, regexp, matching_indicies, splitting_indicies))
end
|
#add_request_method(rm) ⇒ Object
45
46
47
|
# File 'lib/http_router/node.rb', line 45
def add_request_method(rm)
add(RequestMethod.new(@router, self, rm))
end
|
#add_scheme(scheme) ⇒ Object
49
50
51
|
# File 'lib/http_router/node.rb', line 49
def add_scheme(scheme)
add(Scheme.new(@router, self, scheme))
end
|
#add_spanning_match(regexp, matching_indicies = [0], splitting_indicies = nil) ⇒ Object
57
58
59
|
# File 'lib/http_router/node.rb', line 57
def add_spanning_match(regexp, matching_indicies = [0], splitting_indicies = nil)
add(SpanningRegex.new(@router, self, regexp, matching_indicies, splitting_indicies))
end
|
#add_user_agent(uas) ⇒ Object
41
42
43
|
# File 'lib/http_router/node.rb', line 41
def add_user_agent(uas)
add(UserAgent.new(@router, self, uas))
end
|
#add_variable ⇒ Object
25
26
27
|
# File 'lib/http_router/node.rb', line 25
def add_variable
add(Variable.new(@router, self))
end
|
#depth ⇒ Object
94
95
96
|
# File 'lib/http_router/node.rb', line 94
def depth
@parent.send(:depth) + 1
end
|
#inspect ⇒ Object
77
78
79
80
81
82
83
84
|
# File 'lib/http_router/node.rb', line 77
def inspect
ins = "#{' ' * depth}#{inspect_label}"
body = inspect_matchers_body
unless body =~ /^\s*$/
ins << "\n" << body
end
ins
end
|
#inspect_label ⇒ Object
86
87
88
|
# File 'lib/http_router/node.rb', line 86
def inspect_label
"#{self.class.name.split("::").last} (#{@matchers.size} matchers)"
end
|
#inspect_matchers_body ⇒ Object
90
91
92
|
# File 'lib/http_router/node.rb', line 90
def inspect_matchers_body
@matchers.map{ |m| m.inspect}.join("\n")
end
|
#usable?(other) ⇒ Boolean
73
74
75
|
# File 'lib/http_router/node.rb', line 73
def usable?(other)
false
end
|