Class: WebConsole::Response

Inherits:
Struct
  • Object
show all
Defined in:
lib/web_console/response.rb

Overview

A response object that writes content before the closing </body> tag, if possible.

The object quacks like Rack::Response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



6
7
8
# File 'lib/web_console/response.rb', line 6

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



6
7
8
# File 'lib/web_console/response.rb', line 6

def headers
  @headers
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



6
7
8
# File 'lib/web_console/response.rb', line 6

def status
  @status
end

Instance Method Details

#finishObject



19
20
21
# File 'lib/web_console/response.rb', line 19

def finish
  Rack::Response.new(body, status, headers).finish
end

#write(content) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/web_console/response.rb', line 7

def write(content)
  raw_body = Array(body).first.to_s

  if position = raw_body.rindex('</body>')
    raw_body.insert(position, content)
  else
    raw_body << content
  end

  self.body = raw_body
end