Class: Xenon::Request
- Inherits:
-
Object
- Object
- Xenon::Request
- Defined in:
- lib/xenon/request.rb
Instance Attribute Summary collapse
-
#unmatched_path ⇒ Object
Returns the value of attribute unmatched_path.
Instance Method Summary collapse
- #allow_response_body? ⇒ Boolean
- #body ⇒ Object
- #copy(changes = {}) ⇒ Object
- #form_hash ⇒ Object
- #header(name) ⇒ Object
-
#initialize(rack_req) ⇒ Request
constructor
A new instance of Request.
- #param_hash ⇒ Object
- #request_method ⇒ Object
Constructor Details
#initialize(rack_req) ⇒ Request
Returns a new instance of Request.
7 8 9 10 |
# File 'lib/xenon/request.rb', line 7 def initialize(rack_req) @rack_req = rack_req @unmatched_path = rack_req.path.freeze end |
Instance Attribute Details
#unmatched_path ⇒ Object
Returns the value of attribute unmatched_path.
5 6 7 |
# File 'lib/xenon/request.rb', line 5 def unmatched_path @unmatched_path end |
Instance Method Details
#allow_response_body? ⇒ Boolean
44 45 46 |
# File 'lib/xenon/request.rb', line 44 def allow_response_body? request_method != :head end |
#body ⇒ Object
34 35 36 |
# File 'lib/xenon/request.rb', line 34 def body @rack_req.body end |
#copy(changes = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/xenon/request.rb', line 38 def copy(changes = {}) r = dup changes.each { |k, v| r.instance_variable_set("@#{k}", v.freeze) } r end |
#form_hash ⇒ Object
16 17 18 |
# File 'lib/xenon/request.rb', line 16 def form_hash @form_hash ||= @rack_req.POST.with_indifferent_access.freeze end |
#header(name) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/xenon/request.rb', line 25 def header(name) snake_name = name.to_s.tr('-', '_').upcase value = @rack_req.env['HTTP_' + snake_name] || @rack_req.env[snake_name] return nil if value.nil? klass = Xenon::Headers.header_class(name) klass ? klass.parse(value) : Xenon::Headers::Raw.new(name, value) end |
#param_hash ⇒ Object
20 21 22 23 |
# File 'lib/xenon/request.rb', line 20 def param_hash puts "GET = #{@rack_req.GET.inspect}" @param_hash ||= @rack_req.GET.with_indifferent_access.freeze end |
#request_method ⇒ Object
12 13 14 |
# File 'lib/xenon/request.rb', line 12 def request_method @rack_req.request_method.downcase.to_sym end |