summaryrefslogtreecommitdiff
path: root/lib/gitlab/session.rb
blob: 7487ba04a6dcb15f79715ab675fd7e2031f7c99d (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
26
27
# frozen_string_literal: true

module Gitlab
  class Session
    STORE_KEY = :session_storage

    class << self
      def with_session(session)
        old = self.current
        self.current = session
        yield
      ensure
        self.current = old
      end

      def current
        Thread.current[STORE_KEY]
      end

      protected

      def current=(value)
        Thread.current[STORE_KEY] = value
      end
    end
  end
end