Skip to content

Commit

Permalink
Refactor and restyle Flipflop.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolftimmermans committed Mar 4, 2016
1 parent a93fc20 commit a566e10
Show file tree
Hide file tree
Showing 65 changed files with 1,474 additions and 1,109 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.bundle
Gemfile.lock
pkg/*
tmp/*
28 changes: 25 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
language: ruby
rvm:
- 2.3.0
- 2.2.4
- jruby-19mode
- 1.9.3
- 2.0
- 2.1
- 2.2
- 2.3.0
- ruby-head
- jruby-19mode
- jruby-20mode
- rbx-2
matrix:
allow_failures:
- rvm: ruby-head
notifications:
email: false
slack:
secure: crOO1QGnFn9T1DpVgxkukTSiN8lQq09X8WF8oi1Eoa7Liex4gzWq7f8wlIXPrRFAsNjU47fSrz+L1C6Eg068Vd2df9pkqjW0pLNeqUViJ35TzpYISTtzJrX+x3nvCQLlvS4leP6lkijlsvlu1IN0xnXadW5cmcMoEcPo4Yma1RUklwlreSRIEmJiutYKVFRw3gIZA9vsnXNEcD408mvSY/8Kuw+hmRQupODUalXDpZo1q3HH+ZPQq+/rGuJ7XRf9sBtxjpUF0G4FJZQhVP4CrLNYVBE/83rHJ6HSf6u3SlYVIMiautq0nWpVLPHUrkOPJVeVh6EPtoFeI/cehH1NyoAVvL5a39wFRBlJ4jVPWUrrnihJT/6+P6GM9PSnYogxtIoTsdrYES2FgtWGgwG5uLyw8U6bW7G7rCzQwBP7enVHWVCbDgdSSjE1Mg1I9qhRuL6pHs5des4VKk6pfD3p+BRqLmOZR2jx4v8MFwakSFqQWOMxaD0U1lfxecqSx9OkwWEhCFSnHeXeHInEhY6qKCdZZzT+beYn0xppUMPJGMTqe5+po8gL+5MxQwI8Xs/5hSve5frfmuS7UQf5BnFMOzwoThQrXCFRz58wXvcZTD9eTdVBV44Hsi5OLdYn9K58sNUhgcxGfRgdE7Gy9P7DD4fHPGakD/Tz++HuCmCUXNs=
deploy:
provider: rubygems
api_key:
secure: ObuFc5QWnSgraKzYXLT5EhnlGm/+BQ2IN46q3ykXdk8m80ajpWD0/rqtCmu5SiBd6Z56CVZe2zSsEpGhN7/pC5kdG0hYzdpvbgX9IxJNMjYb7rNh2onXdIHVd3yk3qdNgI8hmrgtocJPdtPXqbZSY6KOSH6eb5rPDmA/bWwyREdicW5KN8ZWsXiLzKXoFZ6xvkNFbAjY8AicIfG+dHBFbx+q1xBOvbS44M+VIt/Qsknt9m5CYaWJ0AK/RZoyRhs0F0yYQSLu0mVt7JbHOL05SqQ3uCNlwiEqX+fIiN2mPb24Xxy6SVXr1kD0+H4EZHpgDeUlylO2myYJBFBnjzKXXr0qh3YTxaEKlWO7HnUdnJDRQ+bjyT0USBv7gXO2fEIBN864AGZf+3cL0aKRW3n3cyqrhiUxim7gro7eQSh6t6x5o+LGYw6dDdhR53XIFZoh0s/azYBbgl0bfM3juBMrD3e4w/ieaE9iI+NVj4Z4DYDRtbGIqxsuLwRmSkg3epvBc4Pa7vTDuCyVtd9lpFK55V1TysxhcPu0lqHf+SNnW3+DDwp+CQusQhFIsOcIQdr6PBNSTP5ZtEEqyEMfmt2QK2BEOYUuL6TxIUa9xuu8zMUahSaLOvekM5R+EwW04C3T5hWbPs7W1Ks2jcVzkL2iNd3I18pW9VvkXNAqveuoT28=
gem: tinify
on:
tags: true
repo: voormedia/flipflop
ruby: 2.3.0
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
source "https://rubygems.org"
gemspec

group :test do
gem "actionpack"
gem "railties"
gem "rails"
gem "sqlite3"
gem "minitest"
gem "capybara"
end
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License

Copyright (c) 2011-2013 Learnable Pty Ltd
Copyright (c) 2016 Voormedia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
126 changes: 48 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FlipFlop — flipflop your features
========================
[<img src="https://travis-ci.org/voormedia/flipflop.svg?branch=master" alt="Build Status">](https://travis-ci.org/voormedia/flipflop)

[![Build Status](https://travis-ci.org/pda/flipflop.png)](https://travis-ci.org/pda/flipflop)
# Flipflop your features

**FlipFlop** provides a declarative, layered way of enabling and disabling application functionality at run-time.
**Flipflop** provides a declarative, layered way of enabling and disabling
application functionality at run-time. It is forked from [Flip](https://github.com/pda/flip).

This gem optimizes for:

Expand All @@ -15,92 +15,82 @@ There are three layers of strategies per feature:

* default
* database, to flipflop features site-wide for all users
* cookie, to flipflop features just for you (or someone else)
* cookie, to flipflop features for single users

There is also a configurable system-wide default - !Rails.env.production?` works nicely.

FlipFlop has a dashboard UI that's easy to understand and use.
Flipflop has a dashboard UI that's easy to understand and use.

![Feature FlipFlopper Dashboard](https://cloud.githubusercontent.com/assets/828243/4934741/a5773568-65a4-11e4-98d8-5e9a32720b2e.png)
## Installation

Install
-------
Add the gem to your `Gemfile`:

**Rails 3.0, 3.1 and 3.2+**
```ruby
gem "flipflop"
```

# Gemfile
gem "flipflop"
Generate routes, feature model and databse migration:

# Generate the model and migration
> rails g flipflop:install
```
rails g flipflop:install
```

# Run the migration
> rake db:migrate
Run the migration:

# Include the Feature model, e.g. config/initializers/feature.rb:
require 'feature'
```
rake db:migrate
```

Declaring Features
------------------
Explicitly include the Feature model, e.g. in `config/initializers/feature.rb`:
```
require "feature"
```

## Declaring Features

```ruby
# This is the model class generated by rails g flipflop:install
class Feature < ActiveRecord::Base
include FlipFlop::Declarable
include Flipflop::Declarable

# The recommended FlipFlop strategy stack.
strategy FlipFlop::CookieStrategy
strategy FlipFlop::DatabaseStrategy
strategy FlipFlop::DefaultStrategy
default false
# The recommended Flipflop strategy stack.
strategy Flipflop::CookieStrategy
strategy Flipflop::DatabaseStrategy

# 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

Checking Features
-----------------

`FlipFlop.on?` or the dynamic predicate methods are used to check feature state:
`Flipflop.on?` or the dynamic predicate methods are used to check feature
state:

```ruby
FlipFlop.on? :world_domination # true
FlipFlop.world_domination? # true
Flipflop.on?(:world_domination) # true
Flipflop.world_domination? # true

FlipFlop.on? :shiny_things # false
FlipFlop.shiny_things? # false
Flipflop.on?(:shiny_things) # false
Flipflop.shiny_things? # false
```

Views and controllers use the `feature?(key)` method:
This works everywhere, also in your views and controllers:

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

## Feature Flipflopping Controllers

Feature FlipFlopping Controllers
--------------------------------

The `FlipFlop::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:
The `Flipflop::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:

```ruby
class SampleController < ApplicationController
Expand All @@ -116,8 +106,7 @@ class SampleController < ApplicationController
end
```

Dashboard
---------
## Dashboard

The dashboard provides visibility and control over the features.

Expand All @@ -128,20 +117,21 @@ The gem includes some basic styles:
= stylesheet_link_tag "flipflop"
```

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

app/controllers/admin/features_controller.rb:

```ruby
class Admin::FeaturesController < FlipFlop::FeaturesController
class Admin::FeaturesController < Flipflop::FeaturesController
before_filter :assert_authenticated_as_admin
end
```

app/controllers/admin/strategies_controller.rb:

```ruby
class Admin::StrategiesController < FlipFlop::StrategiesController
class Admin::StrategiesController < Flipflop::StrategiesController
before_filter :assert_authenticated_as_admin
end
```
Expand All @@ -155,29 +145,9 @@ namespace :admin do
end
end

mount FlipFlop::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.
```ruby
extend FlipFlop::Cacheable
mount Flipflop::Engine => "/admin/features"
```

This will ensure that your features are eager loaded with one call to the
database instead of every call to FlipFlop#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.


----
Originally created by Paul Annesley
Copyright © 2011-2013 Learnable Pty Ltd
Copyright © 2016 Voormedia
## License

Licensed with [MIT Licence](http://www.opensource.org/licenses/mit-license.php)
This software is licensed under the MIT License. [View the license](LICENSE).
15 changes: 6 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
require 'bundler'
Bundler::GemHelper.install_tasks
require "bundler/gem_tasks"
require "rake/testtask"

desc "Run all tests"
task :default => :spec

desc "Run specs"
task :spec do
command = "bundle exec rspec --color --format documentation spec/*_spec.rb"
system(command) || raise("specs returned non-zero code")
Rake::TestTask.new do |test|
test.pattern = "test/**/*_test.rb"
end

task default: :test
70 changes: 0 additions & 70 deletions app/assets/stylesheets/flipflop.css

This file was deleted.

5 changes: 5 additions & 0 deletions app/assets/stylesheets/flipflop.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "bootstrap";

section {
margin: 5rem 0 0;
}
Loading

0 comments on commit a566e10

Please sign in to comment.