Flip — flip your features ================ [![Build Status](https://travis-ci.org/pda/flip.png)](https://travis-ci.org/pda/flip) **Flip** provides a declarative, layered way of enabling and disabling application functionality at run-time. This gem optimizes for: * developer ease-of-use, * visibility and control for other stakeholders (like marketing); and * run-time performance There are three layers of strategies per feature: * default * database, to flip features site-wide for all users * cookie, to flip features just for you (or someone else) There is also a configurable system-wide default - !Rails.env.production?` works nicely. Flip has a dashboard UI that's easy to understand and use. ![Feature Flipper Dashboard](https://cloud.githubusercontent.com/assets/828243/4934741/a5773568-65a4-11e4-98d8-5e9a32720b2e.png) Install ------- **Rails 3.0, 3.1 and 3.2+** # Gemfile gem "flip" # Generate the model and migration > rails g flip:install # Run the migration > rake db:migrate # Include the Feature model, e.g. config/initializers/feature.rb: require 'feature' Declaring Features ------------------ ```ruby # This is the model class generated by rails g flip:install class Feature < ActiveRecord::Base include Flip::Declarable # The recommended Flip strategy stack. strategy Flip::CookieStrategy strategy Flip::DatabaseStrategy strategy Flip::DefaultStrategy default false # A basic feature declaration. feature :shiny_things # Override the system-wide default. feature :world_domination, default: true # Enabled half the time..? Sure, we can do that. feature :flakey, default: proc { rand(2).zero? } # Provide a description, normally derived from the feature name. feature :something, default: true, description: "Ability to purchase enrollments in courses" end ``` Checking Features ----------------- `Flip.on?` or the dynamic predicate methods are used to check feature state: ```ruby Flip.on? :world_domination # true Flip.world_domination? # true Flip.on? :shiny_things # false Flip.shiny_things? # false ``` Views and controllers use the `feature?(key)` method: ```erb