beta_feature is a database-based feature flag tool for Ruby on Rails, which allows you check in incomplete features without affecting users.
beta_feature is currently ActiveRecord only.
- PostgreSQL ✅
- MySQL ❌(Working in Progress)
- SQLite ❌(Working in Progress)
Add this line to your application's Gemfile:
gem 'beta_feature'And then execute:
$ bundle
Or install it yourself as:
$ gem install beta_feature
Then, from your Rails app directory, run the following command to complete the setup.
$ rails generate beta_feature:install
$ rake db:migrate
Then, add your feature sets in config/beta_features.yml
dark_mode:
developer: 'ryan@corp.com'
qa: 'windy@corp.com'
status: 'in_progress'
description: 'Building dark mode for my website.'Simply call flagger on your User model:
class User < ActiveRecord::Base
flagger
endThe instance of User will have the ability to toggle feature flags.
user = User.find(327199)
#enable the feature flag dark_mode for this user.
user.enable_beta!(:dark_mode)
#remove landing_page_ux_improvement from this user's feature flags.
user.remove_beta!(:landing_page_ux_improvement)
# check whether a feature is active for a particular user.
user.can_access_beta?(:dark_mode) # => true/falseControll the logic based on feature flag.
if current_user.can_access_beta?(:dark_mode)
render 'home', layout: 'dark'
else
render 'home'
endFor enterprise application, you might want to enable a beta feature for all the employees of specific company. You can do it in this way.
Simply call flagger on your Company model:
class Company < ActiveRecord::Base
flagger
endThe instance of Company will have the ability to toggle feature in company level.
company = Company.find(2)
#enable the feature flag dark_mode for this company.
user.enable_beta!(:dark_mode)
#remove the feature flag landing_page_ux_improvement from this company's feature flags.
user.remove_beta!(:landing_page_ux_improvement)
# check whether a feature is active for this company.
user.can_access_beta?(:dark_mode) # => true/falseControll the logic based on feature flag.
if company.can_access_beta?(:landing_page_ux_improvement)
render 'landing_page_v2'
else
render 'landing_page'
endUser level and company level beta toggles could meet most applications. But if you have special requirements, you can enable feature toggle to any models by calling flagger.
class Group < ActiveRecord::Base
flagger
end
group = Group.find(397)
#enable the feature flag dark_mode for this group.
group.enable_beta!(:dark_mode)
#remove the feature flag landing_page_ux_improvement from this group's feature flags.
group.remove_beta!(:landing_page_ux_improvement)
# check whether a feature is active for this group.
group.can_access_beta?(:dark_mode) # => true/falseAfter checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/helloworld1812/beta_feature. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
| pic | @mention | area |
|---|---|---|
| @xiaoronglv | most things. |
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the BetaFeature project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.