diff options
author | Brett Walker <bwalker@gitlab.com> | 2018-09-04 21:34:37 +0300 |
---|---|---|
committer | Brett Walker <bwalker@gitlab.com> | 2018-09-05 17:19:16 +0300 |
commit | 3aea946e7f590319ff7b85dbbd4eedfc20569deb (patch) | |
tree | 22fd1a021eece3b982b0dfd1f8fe7cce6b5c3df8 /lib | |
parent | 589776fc2e421df12c2526f9cf8cd7f3f239a21f (diff) |
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')
-rw-r--r-- | lib/feature.rb | 12 |
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) |