Class: Apis::Middleware::Response::Json

Inherits:
Object
  • Object
show all
Defined in:
lib/apis/middleware/response/json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil) ⇒ Json

Returns a new instance of Json.



8
9
10
# File 'lib/apis/middleware/response/json.rb', line 8

def initialize(app = nil)
  @app = app
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



7
8
9
# File 'lib/apis/middleware/response/json.rb', line 7

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/apis/middleware/response/json.rb', line 12

def call(env)
  env.body = case env.body
  when ''
    nil
  when 'true'
    true
  when 'false'
    false
  else
    ::MultiJson.decode(env.body)
  end
  @app.call(env) if @app
end