Class: HttpRouter::Node::Request
- Inherits:
-
HttpRouter::Node
- Object
- HttpRouter::Node
- HttpRouter::Node::Request
- Defined in:
- lib/http_router/node/request.rb
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
#node_position, #parent, #priority, #router
Instance Method Summary collapse
-
#initialize(router, parent, opts) ⇒ Request
constructor
A new instance of Request.
- #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, opts) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 |
# File 'lib/http_router/node/request.rb', line 6 def initialize(router, parent, opts) @opts = opts Array(@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.
4 5 6 |
# File 'lib/http_router/node/request.rb', line 4 def opts @opts end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
4 5 6 |
# File 'lib/http_router/node/request.rb', line 4 def request_method @request_method end |
Instance Method Details
#to_code ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/http_router/node/request.rb', line 16 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
12 13 14 |
# File 'lib/http_router/node/request.rb', line 12 def usable?(other) other.class == self.class && other.opts == opts end |