Class: JSONAPI::Rack::N1Warning

Inherits:
Object
  • Object
show all
Defined in:
lib/json_api/rack/n1_warning.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ N1Warning

Returns a new instance of N1Warning.



6
7
8
# File 'lib/json_api/rack/n1_warning.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/json_api/rack/n1_warning.rb', line 10

def call(env)
  return @app.call(env) unless JSONAPI.configuration.n1_warning_enabled
  return @app.call(env) unless jsonapi_request?(env)

  result = nil
  query_count = JSONAPI::QueryCounter.count_queries { result = @app.call(env) }
  status, headers, body = result
  headers = add_n1_headers(headers, query_count, env)
  [status, headers, body]
end