No commit activity in last 3 years
No release in over 3 years
Turn features on or off in various rails environments
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 4.2.0
~> 10.0
~> 3.3.0

Runtime

 Project Readme

ExperimentLight

Code Climate Build Status Gem Version

Turn features on or off in various rails environments

This gem is no longer maintained. Please try my refined feature toggle engine simple_switch.

Installation

Add this line to your application's Gemfile:

gem 'experiment_light'

And then execute:

$ bundle

Or install it yourself as:

$ gem install experiment_light

Usage

Basic

Run install generator:

$ rails generate experiment_light:install

A yaml file named experiment.yml will be added into config/ after running install generator, now your can define your experimental features:

foo:
    development: true
    test: true
    production: false

bar:
    development: false
    test: true
    production: false

Now you can use it in models like this:

class TestModel < ActiveRecord::Base
  ...

  if experiment_on?(:foo)
    def foo_method
      ...
    end
  end

  ...
end

In controllers like this:

class TestController < ApplicationController
  ...

  def index
    ...

    if experiment_on?(:foo)
      redirect_to :back
    end

    ...
  end

  ...
end

And in views like this:

<% if experiment_on?(:foo) %>
    <p>Experiment foo is on</p>
<% end %>

<% if experiment_off?(:bar) %>
    <p>Experiment bar is off</p>
<% end %>

Toggel feature from view

Run install generator:

$ rails generate experiment_light:install_toggle
  • A controller file named experiments_controller.rb will be added into app/controllers

  • A view template file name 'index.html.erb' will be added into app/views/experiments

  • The following two routes will be added:

    get 'experiments' => 'experiments#index'
    post 'update_experiment' => 'experiments#update'

You may want to customize the newly generated files base on your need. Now you are ready to go to localhost:3000/experiments to check out and toggle your features.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/experiment_light/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request