summaryrefslogtreecommitdiff
path: root/lib/feature.rb
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2018-09-04 13:34:37 -0500
committerBrett Walker <bwalker@gitlab.com>2018-09-05 09:19:16 -0500
commit3aea946e7f590319ff7b85dbbd4eedfc20569deb (patch)
tree22fd1a021eece3b982b0dfd1f8fe7cce6b5c3df8 /lib/feature.rb
parent589776fc2e421df12c2526f9cf8cd7f3f239a21f (diff)
downloadgitlab-ce-3aea946e7f590319ff7b85dbbd4eedfc20569deb.tar.gz
add 'default_enabled' to feature flags
This allows you to default a feature flag to 'on' when checking whether it's enabled/disabled.
Diffstat (limited to 'lib/feature.rb')
-rw-r--r--lib/feature.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/feature.rb b/lib/feature.rb
index 24dbcb32fc0..15ce487ad4e 100644
--- a/lib/feature.rb
+++ b/lib/feature.rb
@@ -42,13 +42,17 @@ class Feature
persisted_names.include?(feature.name.to_s)
end
- def enabled?(key, thing = nil)
- get(key).enabled?(thing)
+ def enabled?(key, thing = nil, default_enabled: false)
+ feature = Feature.get(key)
+ return feature.enabled?(thing) unless default_enabled
+
+ # If the feature has been set, always evaluate
+ Feature.persisted?(feature) ? feature.enabled?(thing) : true
end
- def disabled?(key, thing = nil)
+ def disabled?(key, thing = nil, default_enabled: false)
# we need to make different method calls to make it easy to mock / define expectations in test mode
- thing.nil? ? !enabled?(key) : !enabled?(key, thing)
+ thing.nil? ? !enabled?(key, default_enabled: default_enabled) : !enabled?(key, thing, default_enabled: default_enabled)
end
def enable(key, thing = true)