Flips your features based on a redis key, a config/features.yml file or environment variables.
Add can-do to your Gemfile:
# Gemfile
gem "can-do", require: "can_do"To use redis as a storage set the environment variable CANDO_REDIS_URL with your redis instance.
The keys have to be prefixed with 'features:'.
So to set and use the feature experiment-1 set the key like
$ redis-cli SET features:experiment_1 trueand use it like
require "can_do"
CanDo.feature?(:experiment_1)Any unset key will fall back to either the environment variable or the yaml variable and false if none is set.
require "can_do"
CanDo.feature?(:experiment_1)Inside the config folder relative to your working directory create a file called features.yml. Within this file,
place your default feature flags within the defaults key. All available features should be listed here, together with
their default values. Add environment-specific feature flags under the environment name.
# config/features.yml
defaults:
some_feature: false
other_feature: true
development:
some_feature: true
production:
other_feature: false
Check if a feature is enabled by calling CanDo.feature?(:some_feature):
require "can_do"
CanDo.feature?(:some_feature)Or by using a block:
require "can_do"
CanDo.feature?(:some_feature) do
# This block is only evaluated if some_feature is enabled
endIf a feature is not found, false is returned.
You can use environment variables to flip your features. Environment variables always take precedence over anything
within your config/features.yml file.
> RAILS_ENV=development rails console
CanDo.feature?(:some_feature) => false
> SOME_FEATURE=true RAILS_ENV=development rails console
CanDo.feature?(:some_feature) => true
> SOME_FEATURE=true RAILS_ENV=development rails console
CanDo.feature?(:some_feature) => true
> OTHER_FEATURE=true RAILS_ENV=production rails console
CanDo.feature?(:other_feature) => true- Fork it ( https://github.com/blacklane/can-do/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request