gitlab-org--gitlab-foss/lib/declarative_policy/preferred_scope.rb
gfyoung d598e4fd93 Enable more frozen string in lib/**/*.rb
Enables frozen for the following:

* lib/*.rb
* lib/banzai/**/*.rb
* lib/bitbucket/**/*.rb
* lib/constraints/**/*.rb
* lib/container_registry/**/*.rb
* lib/declarative_policy/**/*.rb

Partially addresses #47424.
2018-10-06 17:02:50 -07:00

31 lines
725 B
Ruby

# rubocop:disable Naming/FileName
# frozen_string_literal: true
module DeclarativePolicy
PREFERRED_SCOPE_KEY = :"DeclarativePolicy.preferred_scope"
class << self
def with_preferred_scope(scope)
Thread.current[PREFERRED_SCOPE_KEY], old_scope = scope, Thread.current[PREFERRED_SCOPE_KEY]
yield
ensure
Thread.current[PREFERRED_SCOPE_KEY] = old_scope
end
def preferred_scope
Thread.current[PREFERRED_SCOPE_KEY]
end
def user_scope(&block)
with_preferred_scope(:user, &block)
end
def subject_scope(&block)
with_preferred_scope(:subject, &block)
end
def preferred_scope=(scope)
Thread.current[PREFERRED_SCOPE_KEY] = scope
end
end
end