Class: HttpRouter::Node::Request
- Inherits:
-
HttpRouter::Node
- Object
- HttpRouter::Node
- HttpRouter::Node::Request
- Defined in:
- lib/http_router/node/request.rb
Constant Summary collapse
- VALID_HTTP_VERBS =
%w[HEAD GET DELETE POST PUT OPTIONS PATCH TRACE CONNECT]
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
Attributes inherited from HttpRouter::Node
Instance Method Summary collapse
-
#initialize(router, parent, opts) ⇒ Request
constructor
A new instance of Request.
- #inspect_label ⇒ Object
- #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, #depth, #inspect, #inspect_matchers_body
Constructor Details
#initialize(router, parent, opts) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/http_router/node/request.rb', line 8 def initialize(router, parent, opts) opts.each do |k, v| v = [v] unless v.is_a?(Array) case k when :request_method v.map!{|val| val.to_s.upcase} v.all?{|m| VALID_HTTP_VERBS.include?(m)} or raise InvalidRequestValueError, "Invalid value for request_method #{v.inspect}" v.each{|val| router.known_methods << val} end opts[k] = v end @opts = opts @opts[:request_method].each { |m| router.known_methods << m } if @opts.key?(:request_method) super(router, parent) end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
6 7 8 |
# File 'lib/http_router/node/request.rb', line 6 def opts @opts end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
6 7 8 |
# File 'lib/http_router/node/request.rb', line 6 def request_method @request_method end |
Instance Method Details
#inspect_label ⇒ Object
39 40 41 |
# File 'lib/http_router/node/request.rb', line 39 def inspect_label "#{self.class.name.split("::").last} #{opts.inspect} (#{@matchers.size} matchers)" end |
#to_code ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/http_router/node/request.rb', line 28 def to_code code = "if " code << @opts.map do |k,v| case v.size when 1 then to_code_condition(k, v.first) else "(#{v.map{|vv| to_code_condition(k, vv)}.join(' or ')})" end end * ' and ' code << "\n #{super}\nend" end |
#usable?(other) ⇒ Boolean
24 25 26 |
# File 'lib/http_router/node/request.rb', line 24 def usable?(other) other.class == self.class && other.opts == opts end |