Skip to content

Instantly share code, notes, and snippets.

@subomi
Created February 4, 2019 08:37
Show Gist options
  • Save subomi/04a243ba29f675aee0d02b37f474bd84 to your computer and use it in GitHub Desktop.
Save subomi/04a243ba29f675aee0d02b37f474bd84 to your computer and use it in GitHub Desktop.
configuring a global flipper instance
# config/initializers/flipper.rb
Flipper.configure do |config|
config.default do
adapter = Flipper::Adapters::ActiveRecord.new
Flipper.new(adapter)
end
end
# This setup is primarily for first deployment, because consequently
# we can add new features from the Web UI. However when the DB is changed/crashed
# or in dev mode. This will immediately migrate the default features to be controlled.
def setup_features(features)
features.each do |feature|
if Flipper[feature].exist?
return
end
# Disable feature by default
Flipper[feature].disable
end
end
# A list of features to be deployed on first push
features = ['Feature One', 'Feature Two', 'Feature Three']
if ActiveRecord::Base.connection.data_source_exists? 'flipper_features'
setup_features(features)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment