Module: Gitlab::Ci::YamlProcessor::FeatureFlags

Defined in:
lib/gitlab/ci/yaml_processor/feature_flags.rb

Constant Summary collapse

ACTOR_KEY =
'ci_yaml_processor_feature_flag_actor'
CORRECT_USAGE_KEY =
'ci_yaml_processor_feature_flag_correct_usage'
NO_ACTOR_VALUE =
:no_actor
NO_ACTOR_MESSAGE =
"Actor not set. Ensure to call `enabled?` inside `with_actor` block"
NoActorError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.enabled?(feature_flag) ⇒ Boolean

Use this to check if a feature flag is enabled

Returns:

  • (Boolean)


30
31
32
# File 'lib/gitlab/ci/yaml_processor/feature_flags.rb', line 30

def enabled?(feature_flag)
  ::Feature.enabled?(feature_flag, current_actor)
end

.ensure_correct_usageObject



34
35
36
37
38
39
40
41
# File 'lib/gitlab/ci/yaml_processor/feature_flags.rb', line 34

def ensure_correct_usage
  previous = Thread.current[CORRECT_USAGE_KEY]
  Thread.current[CORRECT_USAGE_KEY] = true

  yield
ensure
  Thread.current[CORRECT_USAGE_KEY] = previous
end

.with_actor(actor) ⇒ Object

Cache a feature flag actor as thread local variable so we can have it available later with #enabled?



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/ci/yaml_processor/feature_flags.rb', line 16

def with_actor(actor)
  previous = Thread.current[ACTOR_KEY]

  # When actor is `nil` the method `Thread.current[]=` does not
  # create the ACTOR_KEY. Instead, we want to still save an explicit
  # value to know that we are within the `with_actor` block.
  Thread.current[ACTOR_KEY] = actor || NO_ACTOR_VALUE

  yield
ensure
  Thread.current[ACTOR_KEY] = previous
end