Class: HttpRouter::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/http_router/node.rb,
lib/http_router/node/glob.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/request.rb,
lib/http_router/node/variable.rb,
lib/http_router/node/arbitrary.rb,
lib/http_router/node/free_regex.rb,
lib/http_router/node/glob_regex.rb,
lib/http_router/node/spanning_regex.rb

Direct Known Subclasses

Arbitrary, FreeRegex, Glob, Lookup, Path, Regex, Request, Root, Variable

Defined Under Namespace

Classes: Arbitrary, FreeRegex, Glob, GlobRegex, Lookup, Path, Regex, Request, Root, SpanningRegex, Variable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router, parent, matchers = []) ⇒ Node

Returns a new instance of Node.



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

def initialize(router, parent, matchers = [])
  @router, @parent, @matchers = router, parent, matchers
end

Instance Attribute Details

#routerObject (readonly)

Returns the value of attribute router.



16
17
18
# File 'lib/http_router/node.rb', line 16

def router
  @router
end

Instance Method Details

#add_arbitrary(blk, allow_partial, param_names) ⇒ Object



39
40
41
# File 'lib/http_router/node.rb', line 39

def add_arbitrary(blk, allow_partial, param_names)
  add(Arbitrary.new(@router, self, allow_partial, blk, param_names))
end

#add_destination(route, path, param_names = []) ⇒ Object



55
56
57
# File 'lib/http_router/node.rb', line 55

def add_destination(route, path, param_names = [])
  add(Path.new(@router, self, route, path, param_names))
end

#add_free_match(regexp) ⇒ Object



51
52
53
# File 'lib/http_router/node.rb', line 51

def add_free_match(regexp)
  add(FreeRegex.new(@router, self, regexp))
end

#add_globObject



26
27
28
# File 'lib/http_router/node.rb', line 26

def add_glob
  add(Glob.new(@router, self))
end

#add_glob_regexp(matcher) ⇒ Object



30
31
32
# File 'lib/http_router/node.rb', line 30

def add_glob_regexp(matcher)
  add(GlobRegex.new(@router, self, matcher))
end

#add_lookup(part) ⇒ Object



59
60
61
# File 'lib/http_router/node.rb', line 59

def add_lookup(part)
  add(Lookup.new(@router, self)).add(part)
end

#add_match(regexp, matching_indicies = [0], splitting_indicies = nil) ⇒ Object



43
44
45
# File 'lib/http_router/node.rb', line 43

def add_match(regexp, matching_indicies = [0], splitting_indicies = nil)
  add(Regex.new(@router, self, regexp, matching_indicies, splitting_indicies))
end

#add_request(opts) ⇒ Object



34
35
36
37
# File 'lib/http_router/node.rb', line 34

def add_request(opts)
  raise unless opts
  add(Request.new(@router, self, opts))
end

#add_spanning_match(regexp, matching_indicies = [0], splitting_indicies = nil) ⇒ Object



47
48
49
# File 'lib/http_router/node.rb', line 47

def add_spanning_match(regexp, matching_indicies = [0], splitting_indicies = nil)
  add(SpanningRegex.new(@router, self, regexp, matching_indicies, splitting_indicies))
end

#add_variableObject



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

def add_variable
  add(Variable.new(@router, self))
end

#depthObject



84
85
86
# File 'lib/http_router/node.rb', line 84

def depth
  @parent.send(:depth) + 1
end

#inspectObject



67
68
69
70
71
72
73
74
# File 'lib/http_router/node.rb', line 67

def inspect
  ins = "#{' ' * depth}#{inspect_label}"
  body = inspect_matchers_body
  unless body =~ /^\s*$/
    ins << "\n" << body
  end
  ins
end

#inspect_labelObject



76
77
78
# File 'lib/http_router/node.rb', line 76

def inspect_label
  "#{self.class.name.split("::").last} (#{@matchers.size} matchers)"
end

#inspect_matchers_bodyObject



80
81
82
# File 'lib/http_router/node.rb', line 80

def inspect_matchers_body
  @matchers.map{ |m| m.inspect}.join("\n")
end

#usable?(other) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/http_router/node.rb', line 63

def usable?(other)
  false
end