• Stars
    star
    403
  • Rank 107,140 (Top 3 %)
  • Language
    Ruby
  • Created over 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flip lets you declare and manage feature flags, backed by cookies (private testing) and database (site-wide).

Flip โ€” flip your features

Build Status

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

Install

Rails >= 4.0

# 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

# This is the model class generated by rails g flip:install
class Feature < ActiveRecord::Base
  extend 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:

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:

<div>
  <% if feature? :world_domination %>
    <%= link_to "Dominate World", world_dominations_path %>
  <% end %>
</div>

Feature Flipping Controllers

The Flip::ControllerFilters module is mixed into the base ApplicationController class. The following controller will respond with 404 Page Not Found to all but the index action unless the :something feature is enabled:

class SampleController < ApplicationController

  require_feature :something, :except => :index

  def show
  end

  def index
  end

end

Dashboard

The dashboard provides visibility and control over the features.

The gem includes some basic styles:

= content_for :stylesheets_head do
  = stylesheet_link_tag "flip"

You probably don't want the dashboard to be public. Here's one way of implementing access control.

app/controllers/admin/features_controller.rb:

class Admin::FeaturesController < Flip::FeaturesController
  before_action :assert_authenticated_as_admin
end

app/controllers/admin/strategies_controller.rb:

class Admin::StrategiesController < Flip::StrategiesController
  before_action :assert_authenticated_as_admin
end

routes.rb:

namespace :admin do
  resources :features, only: [ :index ] do
    resources :strategies, only: [ :update, :destroy ]
  end
end

mount Flip::Engine => "/admin/features"

Cacheable

You can optimize your feature to ensure that it doesn't make a ton of feature calls by adding Cacheable to your model.

extend Flip::Cacheable

This will ensure that your features are eager loaded with one call to the database instead of every call to Flip#on? generating a call to the database. This is helpful if you have a larger Rails application and more than a few features defined.

To start or reset the cache, just call #start_feature_cache.


Created by Paul Annesley Copyright ยฉ 2011-2013 Learnable Pty Ltd, MIT Licence.

More Repositories

1

flexihash

Flexihash is a small PHP library which implements consistent hashing.
PHP
368
star
2

aws-keychain

CLI manager for AWS IAM access keys in Mac OS X keychain; succeeded by https://github.com/99designs/aws-vault
Shell
192
star
3

roflbalt

Canabalt inspired ASCII side-scroller in your console. #railscamp
Ruby
174
star
4

go6502

MOS 6502 emulator in Go.
Go
35
star
5

devise-login-cookie

Devise extension, sets login cookie for easier Single Sign On between same-domain apps.
Ruby
35
star
6

pda6502

Code + notes for a 6502-based breadboard computer.
Assembly
29
star
7

arduino-zero-without-ide

Arduino Zero toolchain without Arduino IDE (Atmel SAM D21 SAMD21G18A)
C
20
star
8

irc_machine

An IRC bot with a RESTful HTTP interface, built on Ruby and EventMachine.
Ruby
19
star
9

signed_json

Encodes and decodes data to a JSON string signed with OpenSSL HMAC. Great for signed cookies.
Ruby
13
star
10

dotvim

pda's vim configuration (deprecated / unmaintained)
Vim Script
10
star
11

c64.rb

Commodore 64 emulator in Ruby
Ruby
8
star
12

cfat16

FAT16 filesystem reader in C
C
8
star
13

cidrinfo

Given an IP CIDR (e.g. 10.20.30.40/20), explain and illustrate the address, network, masks, and host address range.
Go
7
star
14

dcpu16-asm-c

An assembler for DCPU-16, written in C.
C
6
star
15

bringit

PHP user agent for HTTP (unfinished, abandoned)
PHP
6
star
16

am_credit_card

ActiveMerchant::Billing::CreditCard, without ActiveMerchant.
Ruby
5
star
17

pda6502v2

8-bit homebrew computer; version 2
Rust
5
star
18

jsurl

JSUrl aims to encapsulate the reading and manipulating of URLs in JavaScript.
JavaScript
5
star
19

pacc-sinatra

Ruby + Sinatra + CouchDB + Tokyo Tyrant implementation of paul.annesley.cc
Ruby
5
star
20

they_love_you

The game of the decade, by Henrik, Zac and Paul.
JavaScript
5
star
21

avraek

Fundamentally flawed AVR-based USB adapter for Apple Extended Keyboard II
Eagle
4
star
22

bcryphby

A thin CLI wrapper around bcrypt-ruby, and then a thin PHP wrapper around that.
Ruby
4
star
23

digispark-asm

Digispark (attiny85+micronucleus) ASM code/build example.
Assembly
4
star
24

chrome-westpac-password-keyboard

Chrome extension, replaces the terrible Westpac onscreen keyboard with a standard password input.
JavaScript
3
star
25

war2-docker

Run Warcraft II (Battle.net edition) in linux via Docker and Wine
Shell
3
star
26

pacc-django

Django implementation of paul.annesley.cc
Python
2
star
27

dotzsh

Zsh configuration; clone to ~/.zsh and run ~/.zsh/install
Shell
2
star
28

pda.github.com

Paul Annesley - GitHub Pages
2
star
29

avr-led-cube

ATmega328P-powered 4x4x4 LED cube.
Arduino
2
star
30

pacc-piccolo

Implementation of paul.annesley.cc from which the piccolo mico-framework will be extracted.
JavaScript
2
star
31

treasurewar-bot-coffee

Treasure War bot: <canvas> + Socket.IO + CoffeeScript
JavaScript
1
star
32

path_router

Route HTTP requests to backend servers by URL path. [fundamentally flawed]
Ruby
1
star
33

gameoflife-cocoa

Just Messin': Conway's Game of Life in C, with a Cocoa/OpenGL frontend
C
1
star
34

they_love_you-web

Website for they_love_you
CoffeeScript
1
star
35

drztach

Tachometer for DR-Z400SM motorcycle
C
1
star
36

checkproc

A messy process monitoring script, found in a dusty archive
1
star
37

pacc-jekyll

paul.annesley.cc implemented with Jekyll
1
star
38

pacc-octopress

paul.annesley.cc on Octopress
JavaScript
1
star
39

ruby-test-sample

Ruby
1
star
40

pda64

Assembly
1
star
41

sequement

Sequence server in Ruby: fork(), select(), IPC over pipe(), async persistence.
Ruby
1
star
42

rbvm

Basic virtual machine and assembler in Ruby.
Ruby
1
star
43

dotfiles

Miscellaneous system configuration dot files.
Shell
1
star
44

avr-sram

AVR (ATmega328p) interface to 32KiB SRAM via shift registers
C
1
star