Class: Rack::PrettyJSON
- Inherits:
-
Object
- Object
- Rack::PrettyJSON
- Defined in:
- lib/rack/pretty_json.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ PrettyJSON
constructor
You can customize the behavior of
Rack::PrettyJSON
with the options hash.
Constructor Details
#initialize(app, options = {}) ⇒ PrettyJSON
You can customize the behavior of Rack::PrettyJSON
with the options hash.
12 13 14 15 16 17 18 |
# File 'lib/rack/pretty_json.rb', line 12 def initialize(app, = {}) @app = app @options = { :always => false, :with_paramater => 'pretty' }.merge() end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rack/pretty_json.rb', line 20 def call(env) status, headers, body = @app.call(env) headers = Rack::Utils::HeaderHash.new(headers) query_hash = Rack::Utils.parse_nested_query(env['QUERY_STRING']) # If this is a JSON response.. if headers['Content-Type'] == 'application/json' # AND if ANY of the following are true: # - we've been configured to process all JSON responses # - pretty json format has been requested # - we're in development mode if always_process? || requsted_pretty_version?(query_hash) || development? body = make_pretty!(body) end end [status, headers, body] end |