Accept pretty parameter for pretty formatting

If the parameter is equal to `true` (in any case--`TRUE`, `True`) or
a positive integer, return pretty formatted JSON data.

No tests are necessary.
This commit is contained in:
Hiro Asari 2013-11-15 09:19:25 -05:00
parent da62a6ce3c
commit 0e406b3ed1

View File

@ -10,7 +10,13 @@ class Travis::Api::App
def respond_with(resource, options = {})
result = respond(resource, options)
result = JSON.pretty_generate(result) if result && response.content_type =~ /application\/json/
if result && response.content_type =~ /application\/json/
if params[:pretty].downcase == 'true' || params[:pretty].to_i > 0
JSON.pretty_generate(result)
else
result.to_json
end
end
halt result || 404
end