Class: Fenix::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/fenix/core/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject

Returns the value of attribute body.



3
4
5
# File 'lib/fenix/core/response.rb', line 3

def body
  @body
end

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/fenix/core/response.rb', line 4

def headers
  @headers
end

#statusObject

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

#finishObject



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