Class: HttpRouter::RequestNode

Inherits:
Node
  • Object
show all
Defined in:
lib/http_router/node.rb

Constant Summary collapse

RequestMethods =
[:request_method, :host, :port, :scheme]

Instance Attribute Summary collapse

Attributes inherited from Node

#catchall, #extension_node, #linear, #lookup, #request_node, #value, #variable

Instance Method Summary collapse

Methods inherited from Node

#add, #add_extension, #add_request_methods, #initialize, #reset!

Constructor Details

This class inherits a constructor from HttpRouter::Node

Instance Attribute Details

#request_methodObject

Returns the value of attribute request_method.



175
176
177
# File 'lib/http_router/node.rb', line 175

def request_method
  @request_method
end

Instance Method Details

#find_on_request_methods(request) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/http_router/node.rb', line 177

def find_on_request_methods(request)
  if @request_method
    request_value = request.send(request_method)
    if @linear && !@linear.empty?
      next_node = @linear.find do |(regexp, node)|
        regexp === request_value
      end
      next_node &&= next_node.find_on_request_methods(request)
      return next_node if next_node
    end
    if @lookup and next_node = (@lookup[request_value] && @lookup[request_value].find_on_request_methods(request))
      return next_node
    elsif next_node = (@catchall && @catchall.find_on_request_methods(request))
      return next_node
    end
  end
  
  if @value
    self
  else
    current_node = request_method == :request_method ? Response.unmatched(405, {"Allow" => @lookup.keys.join(", ")}) : nil
  end
end