Class: Sinatra::Response
- Inherits:
-
Object
- Object
- Sinatra::Response
- Defined in:
- lib/herbert/Jsonify.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Reference to application instance that created this response.
Instance Method Summary collapse
-
#finish ⇒ Object
Automatically encode body to JSON, but only as long as the content-type remained set to app/json.
- #json? ⇒ Boolean
Instance Attribute Details
#app ⇒ Object
Reference to application instance that created this response
66 67 68 |
# File 'lib/herbert/Jsonify.rb', line 66 def app @app end |
Instance Method Details
#finish ⇒ Object
Automatically encode body to JSON, but only as long as the content-type remained set to app/json
70 71 72 73 74 75 76 77 |
# File 'lib/herbert/Jsonify.rb', line 70 def finish @app.log_request if json? log.h_debug("Serializing response into JSON") @body = [ActiveSupport::JSON.encode(@body)] end super end |
#json? ⇒ Boolean
79 80 81 |
# File 'lib/herbert/Jsonify.rb', line 79 def json? @header['Content-type'] === 'application/json;charset=utf-8' end |