Class: Scorched::Response
- Inherits:
-
Rack::Response
- Object
- Rack::Response
- Scorched::Response
- Defined in:
- lib/scorched/response.rb
Instance Attribute Summary collapse
-
#halted ⇒ Object
Returns the value of attribute halted.
Instance Method Summary collapse
-
#body=(value) ⇒ Object
Automatically wraps the assigned value in an array if it doesn’t respond to “each“.
-
#finish(*args, &block) ⇒ Object
(also: #to_a, #to_ary)
Override finish to avoid using BodyProxy.
-
#merge!(response) ⇒ Object
Merges another response object (or response array) into self in order to preserve references to this response object.
Instance Attribute Details
#halted ⇒ Object
Returns the value of attribute halted.
36 37 38 |
# File 'lib/scorched/response.rb', line 36 def halted @halted end |
Instance Method Details
#body=(value) ⇒ Object
Automatically wraps the assigned value in an array if it doesn’t respond to “each“. Also filters out non-true values and empty strings.
17 18 19 20 |
# File 'lib/scorched/response.rb', line 17 def body=(value) value = [] if !value || value == '' super(value.respond_to?(:each) ? value : [value.to_s]) end |
#finish(*args, &block) ⇒ Object Also known as: to_a, to_ary
Override finish to avoid using BodyProxy
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/scorched/response.rb', line 23 def finish(*args, &block) self['Content-Type'] ||= 'text/html;charset=utf-8' @block = block if block if [204, 205, 304].include?(status.to_i) header.delete "Content-Type" header.delete "Content-Length" close [status.to_i, header, []] else [status.to_i, header, body] end end |
#merge!(response) ⇒ Object
Merges another response object (or response array) into self in order to preserve references to this response object.
5 6 7 8 9 10 11 12 13 |
# File 'lib/scorched/response.rb', line 5 def merge!(response) return self if response == self if Rack::Response === response response = [response.status, response.header, response] end self.status, self.body = response[0], response[2] self.header.merge!(response[1]) self end |