Class: Modern::Request

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/modern/request.rb

Constant Summary collapse

LOCAL_REQUEST_STORE =

rubocop:disable Style/MutableConstant

{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, logger) ⇒ Request

Returns a new instance of Request.



14
15
16
17
18
19
20
# File 'lib/modern/request.rb', line 14

def initialize(env, logger)
  super(env)

  env["HTTP_X_REQUEST_ID"] ||= SecureRandom.uuid

  @logger = logger.child(request_id: request_id)
end

Instance Attribute Details

#loggerObject (readonly)

rubocop:enable Style/MutableConstant



12
13
14
# File 'lib/modern/request.rb', line 12

def logger
  @logger
end

Instance Method Details

#cleanupObject



30
31
32
# File 'lib/modern/request.rb', line 30

def cleanup
  LOCAL_REQUEST_STORE.delete(request_id)
end

#local_storeObject



26
27
28
# File 'lib/modern/request.rb', line 26

def local_store
  LOCAL_REQUEST_STORE[request_id] ||= {}
end

#request_idObject



22
23
24
# File 'lib/modern/request.rb', line 22

def request_id
  env["HTTP_X_REQUEST_ID"]
end