summaryrefslogtreecommitdiff
path: root/lib/feature.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/feature.rb')
-rw-r--r--lib/feature.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/feature.rb b/lib/feature.rb
index 24dbcb32fc0..f4b57376313 100644
--- a/lib/feature.rb
+++ b/lib/feature.rb
@@ -42,13 +42,21 @@ class Feature
persisted_names.include?(feature.name.to_s)
end
- def enabled?(key, thing = nil)
- get(key).enabled?(thing)
+ # use `default_enabled: true` to default the flag to being `enabled`
+ # unless set explicitly. The default is `disabled`
+ def enabled?(key, thing = nil, default_enabled: false)
+ feature = Feature.get(key)
+
+ # If we're not default enabling the flag or the feature has been set, always evaluate.
+ # `persisted?` can potentially generate DB queries and also checks for inclusion
+ # in an array of feature names (177 at last count), possibly reducing performance by half.
+ # So we only perform the `persisted` check if `default_enabled: true`
+ !default_enabled || 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)