⚡️ Lightning
Get started with feature flags in <1 minute. Works with Ruby on Rails. Control who can access features from a simple Web UI or the console. Here's the Web UI:
- Enable (or disable) a feature for everyone
- Enable it for specific models in your database (you can configure which models can be feature flagged)
- Easily hide certain features behind flags
- Lightning stores data on your database so you don't have to worry about availablity (currently works only with
ActiveRecord
)
Install
Add the following link to Gemfile
gem 'lightningff', require: 'lightning'
and run bundle install
.
Script Installation
Run the following script to install the entire feature flag functionality without manual setup for your models (i.e. User, Workspace)
rails lightning:install User Workspace
If you want more control over the setup, run the command below and check out Manual Installation and skip the migrations part
rails lightning:install
Manual Installation
Set up feature flag migrations by running the following lines
bin/rails lightning:install:migrations
bin/rails db:migrate SCOPE=lightning
Create config/initializers/lightning.rb
and set your flaggable entities
Lightning.flaggable_entities = ["User", "Workspace"]
For each flaggable model, add include Lightning::Flaggable
.
class User < ApplicationRecord
include Lightning::Flaggable
end
Usage
user = User.create(name: 'Dummy user')
# Check if feature is enabled for entity
Lightning.enabled?(user, 'homepage_v2')
# Opt in an entity
Lightning.opt_in('homepage_v2', user)
# Opt out an entity
Lightning.opt_out('homepage_v2', user)
# List entities opted in to a feature
Lightning.opt_ins('hompage_v2')
UI Setup
Mount engine in routes.rb
file
Rails.application.routes.draw do
mount Lightning::Engine => "/lightning"
end
API
Create feature (state is disabled)
Lightning.create!('homepage_v2', 'New homepage with better logo')
Find a feature by key
Lightning.get('homepage_v2')
List all features
Lightning.list
Update feature state/description
Lightning.update('homepage_v2', { state: 'enabled_per_entity', description: 'Homepage with new nav' })
Delete feature
Lightning.delete('homepage_v2')
License
The gem is available as open source under the terms of the MIT License.