2014-08-14 17:12:22 +02:00
|
|
|
# Flop
|
|
|
|
|
2014-09-23 17:45:37 +02:00
|
|
|
[![Build Status](https://travis-ci.org/gdott9/flop.svg?branch=master)](https://travis-ci.org/gdott9/flop)
|
|
|
|
|
2014-08-18 12:00:24 +02:00
|
|
|
Flop is a feature flipper gem for ruby.
|
|
|
|
|
|
|
|
Toggle features on and off easily and store feature states in memory or in redis
|
|
|
|
with the different repositories.
|
2014-08-14 17:12:22 +02:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
|
|
|
Add this line to your application's Gemfile:
|
|
|
|
|
|
|
|
gem 'flop'
|
|
|
|
|
|
|
|
And then execute:
|
|
|
|
|
|
|
|
$ bundle
|
|
|
|
|
|
|
|
Or install it yourself as:
|
|
|
|
|
|
|
|
$ gem install flop
|
|
|
|
|
2014-08-18 12:00:24 +02:00
|
|
|
## Repositories
|
2014-08-14 17:43:42 +02:00
|
|
|
|
|
|
|
First, you need to configure where to store everything by setting a repository.
|
|
|
|
|
|
|
|
Available repositories are :
|
|
|
|
- `Flop::Repository::Memory`
|
2014-08-14 18:00:15 +02:00
|
|
|
- `Flop::Repository::Redis`
|
2014-09-01 17:50:35 +02:00
|
|
|
- `Flop::Repository::Yaml`
|
2014-08-14 17:43:42 +02:00
|
|
|
|
|
|
|
To set the repository, create a new object and affect it to `Flop.repo`.
|
|
|
|
```ruby
|
|
|
|
Flop.repo = Flop::Repository::Memory.new
|
2014-08-14 18:00:15 +02:00
|
|
|
|
|
|
|
require 'redis'
|
|
|
|
|
|
|
|
Flop.repo = Flop::Repository::Redis.new(Redis.new)
|
2014-08-14 17:43:42 +02:00
|
|
|
```
|
|
|
|
|
2014-08-18 12:00:24 +02:00
|
|
|
### Redis
|
|
|
|
|
|
|
|
The `Redis` repository requires a `Redis` connection as its first parameter.
|
|
|
|
The default namespace can be passed as a second parameter.
|
|
|
|
|
|
|
|
The default namespace can be a string, an array or a proc.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
Flop::Repository::Redis.new(Redis.new, "flop:namespace")
|
|
|
|
Flop::Repository::Redis.new(Redis.new, [:flop, :namespace])
|
|
|
|
Flop::Repository::Redis.new(Redis.new, -> { ENV['NAMESPACE'] })
|
|
|
|
```
|
|
|
|
|
2014-09-01 17:50:35 +02:00
|
|
|
### YAML
|
|
|
|
|
|
|
|
The `Yaml` repository requires a yaml file as its first parameter.
|
|
|
|
This repository is read-only so methods like `activate`, `toggle`, ... can not be used.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
Flop::Repository::Yaml.new('my_file.yml')
|
|
|
|
```
|
|
|
|
|
2014-08-18 12:00:24 +02:00
|
|
|
## Features
|
2014-08-14 17:43:42 +02:00
|
|
|
|
|
|
|
To access a feature, you can call the Flop[] method or create a new `Flop::Feature` object.
|
|
|
|
```ruby
|
|
|
|
Flop[:example_feature] # is the same as
|
|
|
|
Flop::Feature.new(:example_feature)
|
|
|
|
```
|
|
|
|
|
|
|
|
Available methods on `Flop::Feature` are :
|
|
|
|
- `feature.active?` returns true if the feature is active
|
|
|
|
- `feature.inactive?` returns true if the feature is inactive
|
|
|
|
- `feature.set(boolean)` sets the state of the feature to the passed value
|
|
|
|
- `feature.activate` activates the feature
|
|
|
|
- `feature.deactivate` deactivates the feature
|
|
|
|
- `feature.toggle` toggles the state of the feature
|
|
|
|
- `feature.with { }` executes the block if the feature is active
|
|
|
|
- `feature.without { }` executes the block if the feature is inactive
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
Flop.repo = Flop::Repository::Memory.new
|
|
|
|
|
|
|
|
Flop[:feature].active? # => false
|
|
|
|
Flop[:feature].toggle # => true
|
|
|
|
|
|
|
|
Flop[:feature].with do
|
|
|
|
# code
|
|
|
|
end
|
|
|
|
```
|
2014-08-14 17:12:22 +02:00
|
|
|
|
|
|
|
## Contributing
|
|
|
|
|
|
|
|
1. Fork it ( https://github.com/gdott9/flop/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
|