Class: BatchApi::InternalMiddleware::DecodeJsonBody

Inherits:
Object
  • Object
show all
Defined in:
lib/batch_api/internal_middleware/decode_json_body.rb

Overview

Public: a middleware that decodes the body of any individual batch operation if it’s JSON.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ DecodeJsonBody

Public: initialize the middleware.



7
8
9
# File 'lib/batch_api/internal_middleware/decode_json_body.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/batch_api/internal_middleware/decode_json_body.rb', line 11

def call(env)
  @app.call(env).tap do |result|
    if should_decode?(result)
      result.body = MultiJson.load(result.body)
    end
  end
end