Class: Modern::Response
- Inherits:
-
Rack::Response
- Object
- Rack::Response
- Modern::Response
- Defined in:
- lib/modern/response.rb
Instance Attribute Summary collapse
-
#bypass ⇒ Object
readonly
Returns the value of attribute bypass.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #bypass! ⇒ Object
-
#initialize(request, body = [], status = 200, header = {}) ⇒ Response
constructor
A new instance of Response.
- #json(object, pretty: false) ⇒ Object
- #text(object) ⇒ Object
Constructor Details
#initialize(request, body = [], status = 200, header = {}) ⇒ Response
Returns a new instance of Response.
12 13 14 15 16 17 |
# File 'lib/modern/response.rb', line 12 def initialize(request, body = [], status = 200, header = {}) super(body, status, header) @request = request @bypass = false end |
Instance Attribute Details
#bypass ⇒ Object (readonly)
Returns the value of attribute bypass.
10 11 12 |
# File 'lib/modern/response.rb', line 10 def bypass @bypass end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
9 10 11 |
# File 'lib/modern/response.rb', line 9 def request @request end |
Instance Method Details
#bypass! ⇒ Object
19 20 21 |
# File 'lib/modern/response.rb', line 19 def bypass! @bypass = true end |
#json(object, pretty: false) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/modern/response.rb', line 23 def json(object, pretty: false) headers["Content-Type"] = "application/json" if pretty write(JSON.pretty_generate(object)) else write(JSON.generate(object)) end end |
#text(object) ⇒ Object
33 34 35 36 37 |
# File 'lib/modern/response.rb', line 33 def text(object) headers["Content-Type"] = "text/plain" write(object.to_s) end |