summaryrefslogtreecommitdiff
path: root/lib/gitlab/with_request_store.rb
blob: d13cd9a72f7cdb1309219b665a4c042ca529b731 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

module Gitlab
  module WithRequestStore
    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
      RequestStore.begin!
      yield
    ensure
      RequestStore.end!
      RequestStore.clear!
    end

    extend self
  end
end