Class: JsonKeyTransformerMiddleware::OutgoingJsonFormatter

Inherits:
Middleware
  • Object
show all
Defined in:
lib/json_key_transformer_middleware/outgoing_json_formatter.rb

Instance Method Summary collapse

Methods inherited from Middleware

#camel_to_underscore, #deep_transform_hash_keys, #underscore_to_camel

Constructor Details

#initialize(app) ⇒ OutgoingJsonFormatter



7
8
9
# File 'lib/json_key_transformer_middleware/outgoing_json_formatter.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/json_key_transformer_middleware/outgoing_json_formatter.rb', line 11

def call(env)
  status, headers, body = @app.call(env)

  new_body = body.each.map do |body_part|
    Oj.dump(
      deep_transform_hash_keys(
        Oj.load(body_part), :underscore_to_camel))
  end

  [status, headers, new_body]
end