Class: HttpRouter::Node::Lookup
Instance Attribute Summary
#router
Instance Method Summary
collapse
#add_arbitrary, #add_destination, #add_free_match, #add_glob, #add_glob_regexp, #add_lookup, #add_match, #add_request, #add_spanning_match, #add_variable, #depth, #inspect
Constructor Details
#initialize(router, parent) ⇒ Lookup
Returns a new instance of Lookup.
4
5
6
7
|
# File 'lib/http_router/node/lookup.rb', line 4
def initialize(router, parent)
@map = {}
super(router, parent)
end
|
Instance Method Details
#add(part) ⇒ Object
9
10
11
|
# File 'lib/http_router/node/lookup.rb', line 9
def add(part)
Node.new(@router, self, @map[part] ||= [])
end
|
#inspect_label ⇒ Object
23
24
25
|
# File 'lib/http_router/node/lookup.rb', line 23
def inspect_label
"#{self.class.name}"
end
|
#inspect_matchers_body ⇒ Object
17
18
19
20
21
|
# File 'lib/http_router/node/lookup.rb', line 17
def inspect_matchers_body
@map.map { |key, values|
ins = "#{' ' * depth}when #{key.inspect}:\n"
ins << values.map{|v| v.inspect}.join("\n") }.join("\n")
end
|
#to_code ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/http_router/node/lookup.rb', line 27
def to_code
lookup_ivar = inject_root_ivar(@map)
method_prefix = "lookup_#{root.next_counter} "
inject_root_methods @map.keys.map {|k|
method = :"#{method_prefix}#{k}"
"define_method(#{method.inspect}) do |request|
part = request.path.shift
#{@map[k].map{|n| n.to_code} * "\n"}
request.path.unshift part
end"}.join("\n")
"send(\"#{method_prefix}\#{request.path.first}\", request) if !request.path_finished? && #{lookup_ivar}.key?(request.path.first)"
end
|
#usable?(other) ⇒ Boolean
13
14
15
|
# File 'lib/http_router/node/lookup.rb', line 13
def usable?(other)
other.class == self.class
end
|