Flips your features based on a config/features.yml
file or environment variables. No data store required.
Add can-do
to your Gemfile:
# Gemfile
gem "can-do", require: "can_do"
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
end
If a feature is not found, CanDo::NotAFeature
is raised.
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