diff --git a/app/services/feature_flag.rb b/app/services/feature_flag.rb index 0b0826b27..7aff2bc26 100644 --- a/app/services/feature_flag.rb +++ b/app/services/feature_flag.rb @@ -44,5 +44,13 @@ module FeatureFlag enabled?(feature_flag_name, *args) end + + # Retrieve a list of all currently defined flags and their status. This is + # primarily intended for development and wraps +Flipper.features+. + # + # @return [Hash] the defined flags with their status (+:on+ or +:off+). + def all + Flipper.features.to_h { |feature| [feature.name.to_sym, feature.state] } + end end end diff --git a/spec/services/feature_flag_spec.rb b/spec/services/feature_flag_spec.rb index 7ca000fca..2e207a2f8 100644 --- a/spec/services/feature_flag_spec.rb +++ b/spec/services/feature_flag_spec.rb @@ -99,4 +99,14 @@ describe FeatureFlag, type: :service do end end end + + describe ".all", :aggregate_failures do + it "returns a hash with all feature flags and their status" do + described_class.enable(:flag1) + expect(described_class.all).to eq({ flag1: :on }) + + described_class.disable(:flag2) + expect(described_class.all).to eq({ flag1: :on, flag2: :off }) + end + end end