2020-02-25 13:09:02 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module WithRequestStore
|
2020-04-24 08:10:16 -04:00
|
|
|
def with_request_store(&block)
|
|
|
|
# Skip enabling the request store if it was already active. Whatever
|
|
|
|
# instantiated the request store first is responsible for clearing it
|
|
|
|
return yield if RequestStore.active?
|
|
|
|
|
|
|
|
enabling_request_store(&block)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def enabling_request_store
|
2020-02-25 13:09:02 -05:00
|
|
|
RequestStore.begin!
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
RequestStore.end!
|
|
|
|
RequestStore.clear!
|
|
|
|
end
|
2020-04-24 08:10:16 -04:00
|
|
|
|
|
|
|
extend self
|
2020-02-25 13:09:02 -05:00
|
|
|
end
|
|
|
|
end
|