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



8
9
10
# File 'lib/web_console/response.rb', line 8

def body
  @body
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



8
9
10
# File 'lib/web_console/response.rb', line 8

def headers
  @headers
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



8
9
10
# File 'lib/web_console/response.rb', line 8

def status
  @status
end

Instance Method Details

#finishObject



23
24
25
# File 'lib/web_console/response.rb', line 23

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

#write(content) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/web_console/response.rb', line 9

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

  # We're done with the original body object, so make sure to close it to comply with the Rack SPEC
  body.close if body.respond_to?(:close)

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