Files

HttpRouter::Node::Lookup

Public Class Methods

new(router, parent) click to toggle source
# File lib/http_router/node/lookup.rb, line 4
def initialize(router, parent)
  @map = {}
  super(router, parent)
end

Public Instance Methods

add(part) click to toggle source
# File lib/http_router/node/lookup.rb, line 9
def add(part)
  Node.new(@router, self, @map[part] ||= [])
end
inspect_label() click to toggle source
# File lib/http_router/node/lookup.rb, line 23
def inspect_label
  "#{self.class.name}"
end
inspect_matchers_body() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/http_router/node/lookup.rb, line 13
def usable?(other)
  other.class == self.class
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.