diff options
Diffstat (limited to 'lib/feature.rb')
-rw-r--r-- | lib/feature.rb | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/lib/feature.rb b/lib/feature.rb index d3d972564af..8e9ba5c530a 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -1,10 +1,12 @@ -require 'flipper/adapters/active_record' - class Feature # Classes to override flipper table names class FlipperFeature < Flipper::Adapters::ActiveRecord::Feature # Using `self.table_name` won't work. ActiveRecord bug? superclass.table_name = 'features' + + def self.feature_names + pluck(:key) + end end class FlipperGate < Flipper::Adapters::ActiveRecord::Gate @@ -12,6 +14,8 @@ class Feature end class << self + delegate :group, to: :flipper + def all flipper.features.to_a end @@ -20,32 +24,49 @@ class Feature flipper.feature(key) end + def persisted_names + if RequestStore.active? + RequestStore[:flipper_persisted_names] ||= FlipperFeature.feature_names + else + FlipperFeature.feature_names + end + end + def persisted?(feature) # Flipper creates on-memory features when asked for a not-yet-created one. # If we want to check if a feature has been actually set, we look for it # on the persisted features list. - all.map(&:name).include?(feature.name) + persisted_names.include?(feature.name) end - def enabled?(key) - get(key).enabled? + def enabled?(key, thing = nil) + get(key).enabled?(thing) end - def enable(key) - get(key).enable + def enable(key, thing = true) + get(key).enable(thing) end - def disable(key) - get(key).disable + def disable(key, thing = false) + get(key).disable(thing) + end + + def enable_group(key, group) + get(key).enable_group(group) + end + + def disable_group(key, group) + get(key).disable_group(group) end def flipper - @flipper ||= begin - adapter = Flipper::Adapters::ActiveRecord.new( - feature_class: FlipperFeature, gate_class: FlipperGate) + @flipper ||= Flipper.instance + end - Flipper.new(adapter) - end + # This method is called from config/initializers/flipper.rb and can be used + # to register Flipper groups. + # See https://docs.gitlab.com/ee/development/feature_flags.html#feature-groups + def register_feature_groups end end end |