From 3a122f874205c90ded493840b386bf09c87fe072 Mon Sep 17 00:00:00 2001 From: Alex Stupka Date: Tue, 23 Apr 2024 14:02:40 -0700 Subject: [PATCH 1/2] Check for credentials. * https://github.com/flippercloud/flipper/issues/857 --- lib/flipper/engine.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/flipper/engine.rb b/lib/flipper/engine.rb index f1a1091c..6cdcecba 100644 --- a/lib/flipper/engine.rb +++ b/lib/flipper/engine.rb @@ -39,8 +39,10 @@ def self.default_strict_value initializer "flipper.default", before: :load_config_initializers do |app| # Load cloud secrets from Rails credentials - ENV["FLIPPER_CLOUD_TOKEN"] ||= app.credentials.dig(:flipper, :cloud_token) - ENV["FLIPPER_CLOUD_SYNC_SECRET"] ||= app.credentials.dig(:flipper, :cloud_sync_secret) + if defined?(app.credentials) + ENV["FLIPPER_CLOUD_TOKEN"] ||= app.credentials.dig(:flipper, :cloud_token) + ENV["FLIPPER_CLOUD_SYNC_SECRET"] ||= app.credentials.dig(:flipper, :cloud_sync_secret) + end require 'flipper/cloud' if cloud? From 785a072e09043fde44f96acca59760563db7abbf Mon Sep 17 00:00:00 2001 From: Alex Stupka Date: Wed, 24 Apr 2024 17:31:49 -0700 Subject: [PATCH 2/2] Fix to make active_record adapter work with 4.2 * https://github.com/flippercloud/flipper/issues/858 --- lib/flipper/adapters/active_record.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/flipper/adapters/active_record.rb b/lib/flipper/adapters/active_record.rb index 458b603d..6e7f8753 100644 --- a/lib/flipper/adapters/active_record.rb +++ b/lib/flipper/adapters/active_record.rb @@ -135,7 +135,9 @@ def get_all rows_query = features.join(gates, ::Arel::Nodes::OuterJoin) .on(features[:key].eq(gates[:feature_key])) .project(features[:key].as('feature_key'), gates[:key], gates[:value]) - gates = @feature_class.connection.select_rows(rows_query) + select_method = rails_version_over_4_2? ? :select_rows : :select_all + gates = @feature_class.connection.send(select_method, rows_query) + # group the gates by feature key grouped_gates = gates.inject({}) do |hash, (feature_key, key, value)| @@ -154,6 +156,10 @@ def get_all end end + def rails_version_over_4_2? + Rails::VERSION::MAJOR * 10 + Rails::VERSION::MINOR > 42 + end + # Public: Enables a gate for a given thing. # # feature - The Flipper::Feature for the gate.