Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iguchi1124/cookie_flag
Cookie based feature flags implementation for Rails.
https://github.com/iguchi1124/cookie_flag
rails
Last synced: 17 days ago
JSON representation
Cookie based feature flags implementation for Rails.
- Host: GitHub
- URL: https://github.com/iguchi1124/cookie_flag
- Owner: iguchi1124
- License: mit
- Created: 2018-01-16T11:53:59.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-19T20:07:40.000Z (over 2 years ago)
- Last Synced: 2024-09-23T01:44:38.632Z (about 2 months ago)
- Topics: rails
- Language: Ruby
- Homepage:
- Size: 109 KB
- Stars: 20
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CookieFlag
Cookie based feature flags implementation for Rails.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'cookie_flag'
```And then execute:
```shell
$ bundle
$ bundle exec rails generate cookie_flag:install
```## Usage
At first, edit your `config/cookie_flag.yml` and configure your feature flag name and feature flag secret.
```yml
default: &default
new_feature: '1'development:
<<: *defaulttest:
<<: *defaultproduction:
new_feature: <%= ENV['NEW_FEATURE_SECRET'] %>
```then, you can use cookie based feature flag API at controllers and views.
If you want to enable or disable features from admin page, you can use console web.
Edit your `config/routes.rb`
```rb
Rails.application.routes.draw do
mount CookieFlag::Console, at: "/cookie_flag" if Rails.env.development?
end
```### Controllers
Use `feature` class method at controller, you can return 404 response at disabled feature endpoints.
```rb
class YourFeaturesController < ApplicationController
feature :new_featuredef index
end
end
```And some helper methods `feature_available?` and `feature_flags` are available.
```rb
class NewFeaturesController < ApplicationController
def index
unless feature_available?(:new_feature)
redirect_to root_path
end
end
end
```### Views
`feature_available?` helper method is available.
```erb
<% if feature_available?(:new_feature) %>
you can use new feature!
<% else %>
you cannot use new feature!
<% end %>
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/iguchi1124/cookie_flag.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).