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



60
61
62
# File 'lib/herbert/Jsonify.rb', line 60

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



64
65
66
67
68
69
70
71
# File 'lib/herbert/Jsonify.rb', line 64

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)


73
74
75
# File 'lib/herbert/Jsonify.rb', line 73

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