Build Status Codecov Sponsor

Environment-based feature toggles for Rails

Get it.

Add this line to your application's Gemfile:

gem "foggle"

And then execute:

$ bundle

Or install it yourself as:

$ gem install foggle

Do it.

Add a feature toggle to the environment. The naming convention is FEATURE_{{NAME}}, where {{NAME}} is the feature name you're working on.

Let's say you're working on cool stuff. :sunglasses:

# add to the environment

In your views and controllers, you have access to the method that rules them all: enabled?.

<% if enabled? :cool_stuff %>
  <%= render "cool_stuff" %>
<% end %>

This method just reads in the environment variable you've set. Returns true or false.

There are a couple ways to use foggle, depending on your preference.

feature? is an alias for enabled?.

enabled? :cool_stuff
feature? :cool_stuff

These methods also take strings.

enabled? "cool_stuff"
enabled? "COOL_STUFF"

Passing in a Symbol version of your feature name is recommended, only because it looks cool and Ruby-esque. Do you.


The team at Current wanted a simple feature toggle system without having to integrate a larger feature toggle system into the codebase. Since we are already deploying to Heroku and could quickly modify environment variables across our environments, we thought we'd try this out.



Hack it.


# install dependencies
$ bin/setup

# run Rubocop and tests
$ bundle exec rake spec


Install Foggle locally

$ bundle exec rake install

Deploy Foggle

# bump `foggle/version`
$ bundle exec rake release

Make it.

Bug reports? Ideas? Bring 'em. 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.