Class: HttpRouter::Node::Lookup
- Inherits:
-
HttpRouter::Node
- Object
- HttpRouter::Node
- HttpRouter::Node::Lookup
- Defined in:
- lib/http_router/node/lookup.rb
Instance Attribute Summary
Attributes inherited from HttpRouter::Node
#node_position, #parent, #priority, #router
Instance Method Summary collapse
- #add(part) ⇒ Object
-
#initialize(router, parent) ⇒ Lookup
constructor
A new instance of Lookup.
- #to_code ⇒ Object
- #usable?(other) ⇒ Boolean
Methods inherited from HttpRouter::Node
#add_arbitrary, #add_destination, #add_free_match, #add_glob, #add_glob_regexp, #add_lookup, #add_match, #add_request, #add_spanning_match, #add_variable
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 |
#to_code ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/http_router/node/lookup.rb', line 17 def to_code lookup_ivar = :"@lookup_#{router.next_counter}" inject_root_ivar(lookup_ivar, @map) method_prefix = "lookup_#{router.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") code = " 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 |