A minimalistic Feature Flag engine, cause i was bored of unleash and other overloaded ones.
Add this line to your application's Gemfile:
gem "ffe"And then execute:
$ bundle installCopy over the initializer with:
$ bin/rails g ffe:installand adjust it to your needs. Defaults are:
config.bitlength = 4
config.milieus = { development: 0, staging: 1, production: 2 }
config.env_variable = 'RAILS_ENV'
# actual supported: :solid_queue, :sidekiq
config.queue_adapter = :solid_queue It also adds a loader for feature_flags.json, so you can easily load feature flags from a file.
But to this later under Scenarios.
Install the migration with:
$ bin/rails ffe:install:migrations
$ bin/rails db:migrate(have an eye on the length of the milieu bit mask)
Mount the engine in your application's config/routes.rb file:
mount Ffe::Engine => "/ffe"The engine provides base views for operating on FeatureFlags.
But I recommend implement your own ones, as it is usually easier to customize. See: views/ffe/feature_flags.
Run your app and go to http://localhost:3000/ffe/feature_flags to create your first feature flag.
-
general usage, respecting only the environment
Ffe::FeatureFlag.enabled?(:flag) # or Ffe::FeatureFlag.disabled?(:flag)
-
check if a user is allowed
Ffe::FeatureFlag.enabled_for?(:flag, user: current_user)
Use Case: Cleaning-Up -- The functionality is available to everyone.
Please don't forget to remove feature flags after its use isn't needed anymore.
Every unused feature flag, makes the code noisy and uncomfortable to read and understand.
- Clean up the code after the feature flag has been disabled, or doesn't changed over a long time!
Use Case: A new functionality is to be developed that is accessible to specific users and/or environments via a feature flag.
- Create a feature flag in production
- Dump the flags, then replace the
config/feature_flags.jsonfile locally and commit it. - Continue developing against the feature as before.
Use Case: Functionality is available to only a small number of users.
- Create a feature flag in production, and add allowed users.
- Dump the flags, then replace the
config/feature_flags.jsonfile locally and commit it. - Edit the flag locally and specify a corresponding user.
- Continue developing against the feature as before.
Use Case: Set a feature flag for an announcement, or something similar, for a specific period of time.
This requires the use of ActiveJob; currently, only
SolidQueueandSidekiqadapters are supported. But feel free to add more.
- Create a feature flag in production, but without setting the expires date.
- Dump the flags, then replace the
config/feature_flags.jsonfile locally and commit it. - Continue developing against the feature as before.
- After deployment to production, set the expiration date on the flag -- the flag will be automatically disabled after the expiration date.
Contribution directions go here.
The gem is available as open source under the terms of the MIT License.