Project

toggles

0.01
No release in over a year
YAML-backed implementation of the feature flags pattern. Build a hierarchy of features in YAML files in the filesystem, apply various conditions using boolean logic and a selection of filters, and easily check whether a given feature should be applied.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Toggles

Gem Version CI

YAML backed feature toggles

Installation

Add the following to your Gemfile:

gem "toggles"

and run bundle install from your shell.

To install the gem manually from your shell, run:

gem install toggles

Configuration

Configure toggles:

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:

user:
  id:
    in:
      - 12345
      - 54321

Check if the feature is enabled or disabled:

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.