Class: HttpRouter::Node::Lookup

Inherits:
HttpRouter::Node show all
Defined in:
lib/http_router/node/lookup.rb

Instance Attribute Summary

Attributes inherited from HttpRouter::Node

#router

Instance Method Summary collapse

Methods inherited from HttpRouter::Node

#add_destination, #add_free_match, #add_glob, #add_glob_regexp, #add_host, #add_lookup, #add_match, #add_request_method, #add_scheme, #add_spanning_match, #add_user_agent, #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_labelObject



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

def inspect_label
  "#{self.class.name}"
end

#inspect_matchers_bodyObject



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_codeObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/http_router/node/lookup.rb', line 27

def to_code
  part_name = "part#{root.next_counter}"
  "unless request.path_finished?
    #{part_name} = request.path.shift
    case #{part_name}
      #{@map.map{|k, v| "when #{k.inspect}; #{v.map(&:to_code) * "\n"};"} * "\n"}
    end
    request.path.unshift #{part_name}
  end"
end

#usable?(other) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/http_router/node/lookup.rb', line 13

def usable?(other)
  other.class == self.class
end