https://github.com/easypost/toggles
YAML backed feature toggles
https://github.com/easypost/toggles
Last synced: 11 months ago
JSON representation
YAML backed feature toggles
- Host: GitHub
- URL: https://github.com/easypost/toggles
- Owner: EasyPost
- License: isc
- Created: 2014-12-04T18:13:34.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-10-22T01:47:58.000Z (over 1 year ago)
- Last Synced: 2025-07-02T20:18:35.863Z (11 months ago)
- Language: Ruby
- Homepage:
- Size: 78.1 KB
- Stars: 6
- Watchers: 45
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Toggles
[](https://badge.fury.io/rb/toggles)
[](https://github.com/EasyPost/toggles/actions?query=workflow%3ACI)
YAML backed feature toggles
## Installation
Add the following to your Gemfile:
```ruby
gem "toggles"
```
and run `bundle install` from your shell.
To install the gem manually from your shell, run:
```ruby
gem install toggles
```
## Configuration
Configure `toggles`:
```ruby
Toggles.configure do |config|
config.features_dir = "features"
end
```
You can now express conditional logic within `features_dir`. The structure of the `features_dir` determines the structure of the classes within the `Feature` module. For example if the `features_dir` has the structure:
```
features
├── thing
| ├── one.yml
| └── two.yml
└── test.yml
```
You can call the `Toggles.init` method to force re-parsing the configuration and re-initializing all Features
structures at any time. The `Toggles.reinit_if_necessary` method is a convenience helper which will only
re-initialize of the top-level features directory has changed. Note that, in general, this will only detect
changes if you use a system where you swap out the entire features directory on changes and do not edit
individual files within the directory.
## Usage
Create a file in `features_dir`:
```yaml
user:
id:
in:
- 12345
- 54321
```
Check if the feature is enabled or disabled:
```ruby
Feature.enabled?(:new_feature, :available_for_presentation, user: OpenStruct.new(id: 12345)) # true
Feature.enabled?(:new_feature, :available_for_presentation, user: OpenStruct.new(id: 54321)) # true
Feature.enabled?(:new_feature, :available_for_presentation, user: OpenStruct.new(id: 7)) # false
Feature.disabled?(:new_feature, :available_for_presentation, user: OpenStruct.new(id: 12345)) # false
Feature.disabled?(:new_feature, :available_for_presentation, user: OpenStruct.new(id: 54321)) # false
Feature.disabled?(:new_feature, :available_for_presentation, user: OpenStruct.new(id: 7)) # true
```
## License
This project is licensed under the ISC License, the contents of which can be found at [LICENSE.txt](LICENSE.txt).