Module: Gitlab::TemporarilyAllow

Included in:
GitalyClient::NamespaceService, GitalyClient::StorageSettings
Defined in:
lib/gitlab/temporarily_allow.rb

Constant Summary collapse

TEMPORARILY_ALLOW_MUTEX =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#temporarily_allow(key) ⇒ Object


7
8
9
10
11
12
# File 'lib/gitlab/temporarily_allow.rb', line 7

def temporarily_allow(key)
  temporarily_allow_add(key, 1)
  yield
ensure
  temporarily_allow_add(key, -1)
end

#temporarily_allowed?(key) ⇒ Boolean

Returns:

  • (Boolean)

14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/temporarily_allow.rb', line 14

def temporarily_allowed?(key)
  if Gitlab::SafeRequestStore.active?
    temporarily_allow_request_store[key] > 0
  else
    TEMPORARILY_ALLOW_MUTEX.synchronize do
      temporarily_allow_ivar[key] > 0
    end
  end
end