Class: Ninetails::KeyConversion
- Inherits:
-
Object
- Object
- Ninetails::KeyConversion
- Defined in:
- lib/ninetails/key_conversion.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ KeyConversion
constructor
A new instance of KeyConversion.
- #modify_keys(body) ⇒ Object
Constructor Details
#initialize(app) ⇒ KeyConversion
Returns a new instance of KeyConversion.
4 5 6 |
# File 'lib/ninetails/key_conversion.rb', line 4 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/ninetails/key_conversion.rb', line 8 def call(env) @status, @headers, @response = @app.call(env) if @response.respond_to? :body [@status, @headers, [modify_keys(@response.body)]] else [@status, @headers, @response] end end |
#modify_keys(body) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/ninetails/key_conversion.rb', line 18 def modify_keys(body) if @headers["Content-Type"].include?("application/json") && Ninetails::Config.key_style == :camelcase body = JSON.parse(body).convert_keys -> (key) { key.camelcase :lower } body.to_json else body end end |