Skip to content

Commit

Permalink
add and change logging for flipper initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
rmtolmach committed Sep 23, 2024
1 parent 3c45da5 commit 452e98f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions config/initializers/flipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@

Flipper::UI.configuration.feature_creation_enabled = false
# Make sure that each feature we reference in code is present in the UI, as long as we have a Database already
added_flippers = []
begin
FLIPPER_FEATURE_CONFIG['features'].each do |feature, feature_config|
unless Flipper.exist?(feature)
Flipper.add(feature)
added_flippers.push(feature)

# Default features to enabled for test and those explicitly set for development
if Rails.env.test? || (Rails.env.development? && feature_config['enable_in_development'])
Expand All @@ -57,9 +59,13 @@
Flipper.enable(feature) if Settings.vsp_environment == 'development' && feature_config['enable_in_development']
end

Rails.logger.info "The following feature flippers were added: #{added_flippers}" unless added_flippers.empty?
removed_features = Flipper.features.collect(&:name) - FLIPPER_FEATURE_CONFIG['features'].keys
Rails.logger.warn "Consider removing features no longer in config/features.yml: #{removed_features.join(', ')}"
rescue
unless removed_features.empty?
Rails.logger.warn "Consider removing features no longer in config/features.yml: #{removed_features.join(', ')}"
end
rescue => e
Rails.logger.error "Error processing Flipper features: #{e.message}"
# make sure we can still run rake tasks before table has been created
nil
end
Expand Down

0 comments on commit 452e98f

Please sign in to comment.