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

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

Instance Method Summary collapse

Methods inherited from Node

#add, #add_arbitrary, #add_request_methods, #add_to_linear, #initialize, #reset!

Constructor Details

This class inherits a constructor from HttpRouter::Node

Instance Attribute Details

#request_methodObject

Returns the value of attribute request_method.



205
206
207
# File 'lib/http_router/node.rb', line 205

def request_method
  @request_method
end

Instance Method Details

#find_on_request_methods(request) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/http_router/node.rb', line 207

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 @arbitrary_node
    @arbitrary_node.find_on_arbitrary(request)
  elsif @value
    self
  else
    current_node = request_method == :request_method ? Response.unmatched(405, {"Allow" => @lookup.keys.join(", ")}) : nil
  end
end