Class: Fenix::Response
- Inherits:
-
Object
- Object
- Fenix::Response
- Defined in:
- lib/fenix/core/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #finish ⇒ Object
-
#initialize(body: [], status: 200, headers: { 'Content-Type' => 'text/html; charset=utf-8' }) ⇒ Response
constructor
A new instance of Response.
- #write(string) ⇒ Object
Constructor Details
#initialize(body: [], status: 200, headers: { 'Content-Type' => 'text/html; charset=utf-8' }) ⇒ Response
Returns a new instance of Response.
7 8 9 |
# File 'lib/fenix/core/response.rb', line 7 def initialize(body: [], status: 200, headers: { 'Content-Type' => 'text/html; charset=utf-8' }) @body, @headers, @status = body, headers, status end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/fenix/core/response.rb', line 3 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
4 5 6 |
# File 'lib/fenix/core/response.rb', line 4 def headers @headers end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/fenix/core/response.rb', line 5 def status @status end |
Instance Method Details
#[](key) ⇒ Object
20 21 22 |
# File 'lib/fenix/core/response.rb', line 20 def [](key) @headers[key] end |
#[]=(key, value) ⇒ Object
24 25 26 |
# File 'lib/fenix/core/response.rb', line 24 def []=(key, value) @headers[key] = value end |
#finish ⇒ Object
11 12 13 14 |
# File 'lib/fenix/core/response.rb', line 11 def finish headers['Content-Length'] ||= body.each.map(&:size).inject(0, &:+).to_s [status, headers, body] end |
#write(string) ⇒ Object
16 17 18 |
# File 'lib/fenix/core/response.rb', line 16 def write(string) self.body << string end |