Class: Sinatra::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/herbert/Jsonify.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject

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

#finishObject

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

Returns:

  • (Boolean)


79
80
81
# File 'lib/herbert/Jsonify.rb', line 79

def json?
  @header['Content-type'] === 'application/json;charset=utf-8'
end