flipper 0.20.2 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +9 -1
- data/Changelog.md +59 -0
- data/Gemfile +1 -0
- data/README.md +103 -47
- data/docs/Adapters.md +9 -9
- data/docs/Caveats.md +2 -2
- data/docs/Gates.md +74 -74
- data/docs/Optimization.md +70 -47
- data/docs/http/README.md +12 -11
- data/docs/images/banner.jpg +0 -0
- data/docs/read-only/README.md +8 -5
- data/examples/basic.rb +1 -12
- data/examples/configuring_default.rb +2 -5
- data/examples/dsl.rb +13 -24
- data/examples/enabled_for_actor.rb +8 -15
- data/examples/group.rb +3 -6
- data/examples/group_dynamic_lookup.rb +5 -19
- data/examples/group_with_members.rb +4 -14
- data/examples/importing.rb +1 -1
- data/examples/individual_actor.rb +2 -5
- data/examples/instrumentation.rb +1 -2
- data/examples/memoizing.rb +3 -7
- data/examples/percentage_of_actors.rb +6 -16
- data/examples/percentage_of_actors_enabled_check.rb +7 -10
- data/examples/percentage_of_actors_group.rb +5 -18
- data/examples/percentage_of_time.rb +3 -6
- data/lib/flipper.rb +4 -1
- data/lib/flipper/adapters/memory.rb +20 -94
- data/lib/flipper/adapters/pstore.rb +4 -0
- data/lib/flipper/configuration.rb +33 -7
- data/lib/flipper/errors.rb +2 -3
- data/lib/flipper/identifier.rb +17 -0
- data/lib/flipper/middleware/memoizer.rb +29 -14
- data/lib/flipper/railtie.rb +38 -0
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/memory_spec.rb +21 -1
- data/spec/flipper/configuration_spec.rb +20 -2
- data/spec/flipper/identifier_spec.rb +14 -0
- data/spec/flipper/middleware/memoizer_spec.rb +95 -35
- data/spec/flipper/middleware/setup_env_spec.rb +0 -16
- data/spec/flipper/railtie_spec.rb +69 -0
- data/spec/flipper_spec.rb +0 -1
- data/spec/helper.rb +2 -2
- data/spec/support/spec_helpers.rb +20 -0
- data/test/test_helper.rb +1 -0
- metadata +9 -3
- data/examples/example_setup.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25b07936734df32fbd0331822a97059e76ee9919db287e1073c15b338afc5924
|
4
|
+
data.tar.gz: 221fbb5002318b366d022365b7597f23094d2b50215e9545d3e1c2435faa03ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4529f945a2c71a3c776940cc091e48280e5088e080c203d478aca91e94e52855d4b5c912bae8aad2b7ca95248f42cabf62599a67f307fc98c34faf46c6361bf1
|
7
|
+
data.tar.gz: 3fed3febaf673456551dea59b13b01777f9f59f9ee267424547b495b4d7f06a7cc5c50521431ef29260585c01f93e05f2c1c30c4e55d5833cfb1cb40fccfb7c3
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
name: CI
|
2
|
-
on:
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [master]
|
5
|
+
pull_request:
|
3
6
|
jobs:
|
4
7
|
build:
|
5
8
|
runs-on: ubuntu-latest
|
@@ -19,6 +22,7 @@ jobs:
|
|
19
22
|
RAILS_VERSION: 6.0.0
|
20
23
|
SQLITE3_VERSION: 1.4.1
|
21
24
|
REDIS_URL: redis://localhost:6379/0
|
25
|
+
CI: true
|
22
26
|
steps:
|
23
27
|
- name: Setup memcached
|
24
28
|
uses: KeisukeYamashita/memcached-actions@v1
|
@@ -47,3 +51,7 @@ jobs:
|
|
47
51
|
run: bundle install --jobs 4 --retry 3
|
48
52
|
- name: Run Rake
|
49
53
|
run: bundle exec rake
|
54
|
+
- name: Run Examples
|
55
|
+
env:
|
56
|
+
FLIPPER_CLOUD_TOKEN: ${{ secrets.FLIPPER_CLOUD_TOKEN }}
|
57
|
+
run: script/examples
|
data/Changelog.md
CHANGED
@@ -1,3 +1,62 @@
|
|
1
|
+
## 0.21.0
|
2
|
+
|
3
|
+
### Additions/Changes
|
4
|
+
|
5
|
+
* Default to using memory adapter (https://github.com/jnunemaker/flipper/pull/501)
|
6
|
+
* Adapters now configured on require when possible (https://github.com/jnunemaker/flipper/pull/502)
|
7
|
+
* Added cloud recommendation to flipper-ui. Can be disabled with `Flipper::UI.configure { |config| config.cloud_recommendation = false }`. Just want to raise awareness that more is available if people want it (https://github.com/jnunemaker/flipper/pull/504)
|
8
|
+
* Added default `flipper_id` implementation via `Flipper::Identifier` and automatically included it in ActiveRecord and Sequel models (https://github.com/jnunemaker/flipper/pull/505)
|
9
|
+
* Deprecate superflous sync_method setting (https://github.com/jnunemaker/flipper/pull/511)
|
10
|
+
* Flipper is now pre-configured when used with Rails. By default, it will [memoize and preload all features for each request](docs/Optimization.md#memoization). (https://github.com/jnunemaker/flipper/pull/506)
|
11
|
+
|
12
|
+
### Upgrading
|
13
|
+
|
14
|
+
You should be able to upgrade to 0.21 without any breaking changes. However, if you want to simplify your setup, you can remove some configuration that is now handled automatically:
|
15
|
+
|
16
|
+
1. Adapters are configured when on require, so unless you are using caching or other customizations, you can remove adapter configuration.
|
17
|
+
|
18
|
+
```diff
|
19
|
+
# config/initializers/flipper.rb
|
20
|
+
- Flipper.configure do |config|
|
21
|
+
- config.default { Flipper.new(Flipper::Adapters::ActiveRecord.new) }
|
22
|
+
- end
|
23
|
+
```
|
24
|
+
|
25
|
+
2. `Flipper::Middleware::Memoizer` will be enabled by default.
|
26
|
+
|
27
|
+
```diff
|
28
|
+
# config/initializers/flipper.rb
|
29
|
+
- Rails.configuration.middleware.use Flipper::Middleware::Memoizer,
|
30
|
+
- preload: [:stats, :search, :some_feature]
|
31
|
+
+ Rails.application.configure do
|
32
|
+
+ # Uncomment to configure which features to preload on all requests
|
33
|
+
+ # config.flipper.preload = [:stats, :search, :some_feature]
|
34
|
+
+ end
|
35
|
+
```
|
36
|
+
|
37
|
+
3. `#flipper_id`, which is used to enable features for specific actors, is now defined by [Flipper::Identifier](lib/flipper/identifier.rb) on all ActiveRecord and Sequel models. You can remove your implementation if it is in the form of `ModelName;id`.
|
38
|
+
|
39
|
+
4. When using `flipper-cloud`, The `Flipper::Cloud.app` webhook receiver is now mounted at `/_flipper` by default.
|
40
|
+
|
41
|
+
```diff
|
42
|
+
# config/routes.rb
|
43
|
+
- mount Flipper::Cloud.app, at: "/_flipper"
|
44
|
+
```
|
45
|
+
|
46
|
+
## 0.20.4
|
47
|
+
|
48
|
+
### Additions/Changes
|
49
|
+
|
50
|
+
* Allow actors and time gates to deal with decimal percentages (https://github.com/jnunemaker/flipper/pull/492)
|
51
|
+
* Change Flipper::Cloud::Middleware to receive webhooks at / in addition to /webhooks.
|
52
|
+
* Add `write_through` option to ActiveSupportCacheStore adapter to support write-through caching (https://github.com/jnunemaker/flipper/pull/512)
|
53
|
+
|
54
|
+
## 0.20.3
|
55
|
+
|
56
|
+
### Additions/Changes
|
57
|
+
|
58
|
+
* Changed the internal structure of how the memory adapter stores things.
|
59
|
+
|
1
60
|
## 0.20.2
|
2
61
|
|
3
62
|
### Additions/Changes
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,23 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
~---~~~~----~~~~ ~~
|
16
|
-
</pre>
|
17
|
-
|
18
|
-
Feature flipping is the act of enabling or disabling features or parts of your application, ideally without re-deploying or changing anything in your code base.
|
19
|
-
|
20
|
-
The goal of this gem is to make turning features on or off so easy that everyone does it. Whatever your data store, throughput, or experience, feature flipping should be easy and have minimal impact on your application.
|
1
|
+
[![Flipper Mark](docs/images/banner.jpg)](https://www.flippercloud.io)
|
2
|
+
|
3
|
+
# Flipper
|
4
|
+
|
5
|
+
> Beautiful, performant feature flags for Ruby.
|
6
|
+
|
7
|
+
Flipper gives you control over who has access to features in your app.
|
8
|
+
|
9
|
+
* Enable or disable features for everyone, specific actors, groups of actors, a percentage of actors, or a percentage of time.
|
10
|
+
* Configure your feature flags from the console or a web UI.
|
11
|
+
* Regardless of what data store you are using, Flipper can performantly store your feature flags.
|
12
|
+
* Use [Flipper Cloud](#flipper-cloud) to cascade features from multiple environments, share settings with your team, control permissions, keep an audit history, and rollback.
|
13
|
+
|
14
|
+
Control your software — don't let it control you.
|
21
15
|
|
22
16
|
## Installation
|
23
17
|
|
@@ -25,6 +19,10 @@ Add this line to your application's Gemfile:
|
|
25
19
|
|
26
20
|
gem 'flipper'
|
27
21
|
|
22
|
+
You'll also want to pick a storage [adapter](#adapters), for example:
|
23
|
+
|
24
|
+
gem 'flipper-active_record'
|
25
|
+
|
28
26
|
And then execute:
|
29
27
|
|
30
28
|
$ bundle
|
@@ -33,50 +31,108 @@ Or install it yourself with:
|
|
33
31
|
|
34
32
|
$ gem install flipper
|
35
33
|
|
36
|
-
##
|
34
|
+
## Getting Started
|
37
35
|
|
38
|
-
|
36
|
+
Use `Flipper#enabled?` in your app to check if a feature is enabled.
|
39
37
|
|
40
38
|
```ruby
|
41
|
-
require 'flipper'
|
42
|
-
|
43
|
-
Flipper.configure do |config|
|
44
|
-
config.default do
|
45
|
-
# pick an adapter, this uses memory, any will do
|
46
|
-
adapter = Flipper::Adapters::Memory.new
|
47
|
-
|
48
|
-
# pass adapter to handy DSL instance
|
49
|
-
Flipper.new(adapter)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
39
|
# check if search is enabled
|
54
|
-
if Flipper.enabled?
|
40
|
+
if Flipper.enabled? :search, current_user
|
55
41
|
puts 'Search away!'
|
56
42
|
else
|
57
43
|
puts 'No search for you!'
|
58
44
|
end
|
45
|
+
```
|
59
46
|
|
60
|
-
|
61
|
-
Flipper.enable(:search)
|
47
|
+
All features are disabled by default, so you'll need to explicitly enable them.
|
62
48
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
49
|
+
#### Enable a feature for everyone
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
Flipper.enable :search
|
53
|
+
```
|
54
|
+
|
55
|
+
#### Enable a feature for a specific actor
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
Flipper.enable_actor :search, current_user
|
59
|
+
```
|
60
|
+
|
61
|
+
#### Enable a feature for a group of actors
|
62
|
+
|
63
|
+
First tell Flipper about your groups:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
# config/initializers/flipper.rb
|
67
|
+
Flipper.register(:admin) do |actor|
|
68
|
+
actor.respond_to?(:admin?) && actor.admin?
|
68
69
|
end
|
69
70
|
```
|
70
71
|
|
71
|
-
|
72
|
+
Then enable the feature for that group:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
Flipper.enable_group :search, :admin
|
76
|
+
```
|
77
|
+
|
78
|
+
#### Enable a feature for a percentage of actors
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
Flipper.enable_percentage_of_actors :search, 2
|
82
|
+
```
|
83
|
+
|
84
|
+
|
85
|
+
Read more about enabling and disabling features with [Gates](docs/Gates.md). Check out the [examples directory](examples/) for more, and take a peek at the [DSL](lib/flipper/dsl.rb) and [Feature](lib/flipper/feature.rb) classes for code/docs.
|
86
|
+
|
87
|
+
## Adapters
|
88
|
+
|
89
|
+
Flipper is built on adapters for maximum flexibility. Regardless of what data store you are using, Flipper can performantly store data in it.
|
90
|
+
|
91
|
+
Pick one of our [supported adapters](docs/Adapters.md#officially-supported) and follow the installation instructions:
|
92
|
+
|
93
|
+
* [Active Record](docs/active_record/README.md)
|
94
|
+
* [Sequel](docs/sequel/README.md)
|
95
|
+
* [Redis](docs/redis/README.md)
|
96
|
+
* [Mongo](docs/mongo/README.md)
|
97
|
+
* [Moneta](docs/moneta/README.md)
|
98
|
+
* [Rollout](docs/rollout/README.md)
|
99
|
+
|
100
|
+
Or [roll your own](docs/Adapters.md#roll-your-own). We even provide automatic (rspec and minitest) tests for you, so you know you've built your custom adapter correctly.
|
101
|
+
|
102
|
+
Read more about [Adapters](docs/Adapters.md).
|
103
|
+
|
104
|
+
## Flipper UI
|
105
|
+
|
106
|
+
If you prefer a web UI to an IRB console, you can setup the [Flipper UI](docs/ui/README.md).
|
107
|
+
|
108
|
+
It's simple and pretty.
|
109
|
+
|
110
|
+
![Flipper UI Screenshot](docs/ui/images/feature.png)
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
## Flipper Cloud
|
115
|
+
|
116
|
+
Or, (even better than OSS + UI) use [Flipper Cloud](https://www.flippercloud.io) which comes with:
|
117
|
+
|
118
|
+
* **everything in one place** — no need to bounce around from different application UIs or IRB consoles.
|
119
|
+
* **permissions** — grant access to everyone in your organization or lockdown each project to particular people.
|
120
|
+
* **multiple environments** — production, staging, enterprise, by continent, whatever you need.
|
121
|
+
* **personal environments** — no more rake scripts or manual enable/disable to get your laptop to look like production. Every developer gets a personal environment that inherits from production that they can override as they please ([read more](https://www.johnnunemaker.com/flipper-cloud-environments/)).
|
122
|
+
* **no maintenance** — we'll keep the lights on for you. We also have handy webhooks for keeping your app in sync with Cloud, so **our availability won't affect yours**. All your feature flag reads are local to your app.
|
123
|
+
* **audit history** — every feature change and who made it.
|
124
|
+
* **rollbacks** — enable or disable a feature accidentally? No problem. You can roll back to any point in the audit history with a single click.
|
125
|
+
|
126
|
+
[![Flipper Cloud Screenshot](docs/images/flipper_cloud.png)](https://www.flippercloud.io)
|
127
|
+
|
128
|
+
Cloud is super simple to integrate with Rails ([demo app](https://github.com/fewerandfaster/flipper-rails-demo)), Sinatra or any other framework.
|
129
|
+
|
130
|
+
## Advanced
|
72
131
|
|
73
|
-
|
132
|
+
A few miscellaneous docs with more info for the hungry.
|
74
133
|
|
75
|
-
* [Gates](docs/Gates.md) - Boolean, Groups, Actors, % of Actors, and % of Time
|
76
|
-
* [Adapters](docs/Adapters.md) - Mongo, Redis, Cassandra, Active Record...
|
77
134
|
* [Instrumentation](docs/Instrumentation.md) - ActiveSupport::Notifications and Statsd
|
78
135
|
* [Optimization](docs/Optimization.md) - Memoization middleware and Cache adapters
|
79
|
-
* [Web Interface](docs/ui/README.md) - Point and click...
|
80
136
|
* [API](docs/api/README.md) - HTTP API interface
|
81
137
|
* [Caveats](docs/Caveats.md) - Flipper beware! (see what I did there)
|
82
138
|
* [Docker-Compose](docs/DockerCompose.md) - Using docker-compose in contributing
|
data/docs/Adapters.md
CHANGED
@@ -4,17 +4,17 @@ I plan on supporting the adapters in the flipper repo. Other adapters are welcom
|
|
4
4
|
|
5
5
|
## Officially Supported
|
6
6
|
|
7
|
-
* [ActiveRecord adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_record) - Rails
|
8
|
-
* [
|
9
|
-
* [
|
10
|
-
* [Http adapter](https://github.com/jnunemaker/flipper/blob/master/docs/http)
|
11
|
-
* [memory adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/memory.rb) – great for tests
|
12
|
-
* [Moneta adapter](https://github.com/jnunemaker/flipper/blob/master/docs/moneta)
|
7
|
+
* [ActiveRecord adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_record) - Rails 5 and 6.
|
8
|
+
* [Sequel adapter](https://github.com/jnunemaker/flipper/blob/master/docs/sequel)
|
9
|
+
* [Redis adapter](https://github.com/jnunemaker/flipper/blob/master/docs/redis)
|
13
10
|
* [Mongo adapter](https://github.com/jnunemaker/flipper/blob/master/docs/mongo)
|
14
11
|
* [PStore adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/pstore.rb) – great for when a local file is enough
|
15
|
-
* [
|
16
|
-
* [
|
17
|
-
* [
|
12
|
+
* [Http adapter](https://github.com/jnunemaker/flipper/blob/master/docs/http) - great for using with `Flipper::Api`
|
13
|
+
* [Moneta adapter](https://github.com/jnunemaker/flipper/blob/master/docs/moneta) - great for a variety of data stores
|
14
|
+
* [ActiveSupportCacheStore adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_support_cache_store) - great for Rails caching
|
15
|
+
* [Memory adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/memory.rb) – great for tests
|
16
|
+
* [Read-only adapter](https://github.com/jnunemaker/flipper/blob/master/docs/read-only) - great for preventing writes from production console
|
17
|
+
* [Rollout adapter](rollout/README.md) - great for switching from rollout to flipper
|
18
18
|
|
19
19
|
## Community Supported
|
20
20
|
|
data/docs/Caveats.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
# Caveats
|
2
2
|
|
3
|
-
1. The [individual actor gate](https://github.com/jnunemaker/flipper/blob/master/docs/Gates.md#2-individual-actor) is typically not designed for hundreds or thousands of actors to be enabled. This is an explicit choice to make it easier to batch load data from the adapters instead of performing individual checks for actors over and over. If you need to enable something for more than
|
4
|
-
2. The disable method exists only to clear something that is enabled. If the thing you are disabling is not enabled, the disable is pointless. This means that if you enable one group an actor is in and disable another group, the feature will be enabled for the actor. ([related issue](https://github.com/jnunemaker/flipper/issues/71))
|
3
|
+
1. The [individual actor gate](https://github.com/jnunemaker/flipper/blob/master/docs/Gates.md#2-individual-actor) is typically not designed for hundreds or thousands of actors to be enabled. This is an explicit choice to make it easier to batch load data from the adapters instead of performing individual checks for actors over and over. If you need to enable something for more than 100 individual actors, I would recommend using a [group](https://github.com/jnunemaker/flipper/blob/master/docs/Gates.md#5-group).
|
4
|
+
2. The `disable` method exists only to clear something that is enabled. If the thing you are disabling is not enabled, the disable is pointless. This means that if you enable one group an actor is in and disable another group, the feature will be enabled for the actor. ([related issue](https://github.com/jnunemaker/flipper/issues/71))
|
data/docs/Gates.md
CHANGED
@@ -7,76 +7,82 @@ Out of the box several types of enabling are supported. They are checked in this
|
|
7
7
|
All on or all off. Think top level things like `:stats`, `:search`, `:logging`, etc. Also, an easy way to release a new feature as once a feature is boolean enabled it is on for every situation.
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
flipper[:stats].enabled? # check
|
10
|
+
Flipper.enable :stats # turn on
|
11
|
+
Flipper.disable :stats # turn off
|
12
|
+
Flipper.enabled? :stats # check
|
14
13
|
```
|
15
14
|
|
16
15
|
## 2. Individual Actor
|
17
16
|
|
18
|
-
Turn feature on for individual thing. Think enable feature for someone to test or for a buddy.
|
17
|
+
Turn feature on for individual thing. Think enable feature for someone to test or for a buddy.
|
19
18
|
|
20
19
|
```ruby
|
21
|
-
|
20
|
+
Flipper.enable_actor :stats, user
|
21
|
+
Flipper.enabled? :stats, user # true
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
flipper[:stats].disable user
|
27
|
-
flipper[:stats].enabled? user # false
|
23
|
+
Flipper.disable_actor :stats, user
|
24
|
+
Flipper.enabled? :stats, user # false
|
28
25
|
|
29
26
|
# you can enable anything, does not need to be user or person
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# you can also use shortcut methods
|
34
|
-
flipper.enable_actor :search, user
|
35
|
-
flipper.disable_actor :search, user
|
36
|
-
flipper[:search].enable_actor user
|
37
|
-
flipper[:search].disable_actor user
|
38
|
-
```
|
27
|
+
Flipper.enable_actor :search, organization
|
28
|
+
Flipper.enabled? :search, organization
|
39
29
|
|
40
|
-
|
30
|
+
# you can also save a reference to a specific feature
|
31
|
+
feature = Flipper[:search]
|
32
|
+
|
33
|
+
feature.enable_actor user
|
34
|
+
feature.enabled? user # true
|
35
|
+
feature.disable_actor user
|
36
|
+
```
|
41
37
|
|
42
|
-
The
|
38
|
+
The only requirement for an individual actor is that it must have a unique `flipper_id`. Include the `Flipper::Identifier` module for a default implementation which combines the class name and `id` (e.g. `User;6`).
|
43
39
|
|
44
40
|
```ruby
|
45
|
-
class User
|
46
|
-
|
47
|
-
"User;#{id}"
|
48
|
-
end
|
41
|
+
class User < Struct.new(:id)
|
42
|
+
include Flipper::Identifier
|
49
43
|
end
|
50
44
|
|
51
|
-
|
45
|
+
User.new(5).flipper_id # => "User;5"
|
46
|
+
```
|
47
|
+
|
48
|
+
You can also define your own implementation:
|
49
|
+
|
50
|
+
```
|
51
|
+
class Organization < Struct.new(:uuid)
|
52
52
|
def flipper_id
|
53
|
-
|
53
|
+
uuid
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
Organization.new("DEB3D850-39FB-444B-A1E9-404A990FDBE0").flipper_id
|
58
|
+
# => "DEB3D850-39FB-444B-A1E9-404A990FDBE0"
|
56
59
|
```
|
57
60
|
|
61
|
+
Just make sure each type of object has a unique `flipper_id`.
|
62
|
+
|
58
63
|
## 3. Percentage of Actors
|
59
64
|
|
60
65
|
Turn this on for a percentage of actors (think user, member, account, group, whatever). Consistently on or off for this user as long as percentage increases. Think slow rollout of a new feature to a percentage of things.
|
61
66
|
|
62
67
|
```ruby
|
63
|
-
flipper = Flipper.new(adapter)
|
64
|
-
|
65
|
-
# returns a percentage of actors instance set to 10
|
66
|
-
percentage = flipper.actors(10)
|
67
|
-
|
68
68
|
# turn stats on for 10 percent of users in the system
|
69
|
-
|
69
|
+
Flipper.enable :stats, Flipper.actors(10)
|
70
|
+
# or
|
71
|
+
Flipper.enable_percentage_of_actors :stats, 10
|
70
72
|
|
71
73
|
# checks if actor's flipper_id is in the enabled percentage by hashing
|
72
74
|
# user.flipper_id.to_s to ensure enabled distribution is smooth
|
73
|
-
|
75
|
+
Flipper.enabled? :stats, user
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
Flipper.disable_percentage_of_actors :search # sets to 0
|
78
|
+
# or
|
79
|
+
Flipper.disable :stats, Flipper.actors(0)
|
80
|
+
|
81
|
+
# you can also save a reference to a specific feature
|
82
|
+
feature = Flipper[:search]
|
83
|
+
feature.enable_percentage_of_actors 10
|
84
|
+
feature.enabled? user
|
85
|
+
feature.disable_percentage_of_actors # sets to 0
|
80
86
|
```
|
81
87
|
|
82
88
|
## 4. Percentage of Time
|
@@ -84,22 +90,20 @@ flipper[:search].disable_percentage_of_actors # sets to 0
|
|
84
90
|
Turn this on for a percentage of time. Think load testing new features behind the scenes and such.
|
85
91
|
|
86
92
|
```ruby
|
87
|
-
flipper = Flipper.new(adapter)
|
88
|
-
|
89
|
-
# get percentage of time instance set to 5
|
90
|
-
percentage = flipper.time(5)
|
91
|
-
|
92
93
|
# Register a feature called logging and turn it on for 5 percent of the time.
|
93
94
|
# This could be on during one request and off the next
|
94
95
|
# could even be on first time in request and off second time
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
96
|
+
Flipper.enable_percentage_of_time :logging, 5
|
97
|
+
|
98
|
+
Flipper.enabled? :logging # this will return true 5% of the time.
|
99
|
+
|
100
|
+
Flipper.disable_percentage_of_time :logging # sets to 0
|
101
|
+
|
102
|
+
# you can also save a reference to a specific feature
|
103
|
+
feature = Flipper[:search]
|
104
|
+
feature.enable_percentage_of_time, 5
|
105
|
+
feature.enabled?
|
106
|
+
feature.disable_percentage_of_time
|
103
107
|
```
|
104
108
|
|
105
109
|
Timeness is not a good idea for enabling new features in the UI. Most of the time you want a feature on or off for a user, but there are definitely times when I have found percentage of time to be very useful.
|
@@ -114,52 +118,48 @@ Flipper.register(:admins) do |actor|
|
|
114
118
|
actor.respond_to?(:admin?) && actor.admin?
|
115
119
|
end
|
116
120
|
|
117
|
-
|
118
|
-
|
119
|
-
flipper[:stats].enable flipper.group(:admins) # This registers a stats feature and turns it on for admins (which is anything that returns true from the registered block).
|
120
|
-
flipper[:stats].disable flipper.group(:admins) # turn off the stats feature for admins
|
121
|
+
Flipper.enable_group :stats, :admins # This registers a stats feature and turns it on for admins (which is anything that returns true from the registered block).
|
122
|
+
Flipper.disable_group :stats, :admins # turn off the stats feature for admins
|
121
123
|
|
122
124
|
person = Person.find(params[:id])
|
123
|
-
|
125
|
+
Flipper.enabled? :stats, person # check if enabled, returns true if person.admin? is true
|
124
126
|
|
125
|
-
# you can also use shortcut methods. This also registers a stats feature and turns it on for admins.
|
126
|
-
flipper.enable_group :stats, :admins
|
127
|
-
person = Person.find(params[:id])
|
128
|
-
flipper[:stats].enabled? person # same as above. check if enabled, returns true if person.admin? is true
|
129
127
|
|
130
|
-
|
131
|
-
|
132
|
-
|
128
|
+
# you can also use shortcut methods. This also registers a stats feature and turns it on for admins.
|
129
|
+
feature = Flipper[:search]
|
130
|
+
feature.enable_group :admins
|
131
|
+
feature.enabled? person
|
132
|
+
feature.disable_group :admins
|
133
133
|
```
|
134
134
|
|
135
135
|
Here's a quick explanation of the above code block:
|
136
136
|
|
137
|
-
```
|
137
|
+
```ruby
|
138
138
|
Flipper.register(:admins) do |actor|
|
139
139
|
actor.respond_to?(:admin?) && actor.admin?
|
140
140
|
end
|
141
141
|
```
|
142
|
-
- The above first registers a group called `admins` which essentially saves a [Proc](http://www.eriktrautman.com/posts/ruby-explained-blocks-procs-and-lambdas-aka-closures) to be called later. The `actor` is an instance of the `Flipper::Types::Actor` that wraps the thing being checked against and `actor.thing` is the original object being checked.
|
142
|
+
- The above first registers a group called `admins` which essentially saves a [Proc](http://www.eriktrautman.com/posts/ruby-explained-blocks-procs-and-lambdas-aka-closures) to be called later. The `actor` is an instance of the `Flipper::Types::Actor` that wraps the thing being checked against and `actor.thing` is the original object being checked.
|
143
143
|
|
144
|
-
```
|
145
|
-
|
144
|
+
```ruby
|
145
|
+
Flipper.enable_group :stats, :admins
|
146
146
|
```
|
147
147
|
|
148
148
|
- The above enables the stats feature to any object that returns true from the `:admins` proc.
|
149
149
|
|
150
|
-
```
|
150
|
+
```ruby
|
151
151
|
person = Person.find(params[:id])
|
152
|
-
|
152
|
+
Flipper.enabled? :stats, person # check if person is enabled, returns true if person.admin? is true
|
153
153
|
```
|
154
154
|
|
155
|
-
When the `person` object is passed to the `enabled?` method, it is then passed into the proc. If the proc returns true, the entire statement returns true and so `
|
155
|
+
When the `person` object is passed to the `enabled?` method, it is then passed into the proc. If the proc returns true, the entire statement returns true and so `Flipper[:stats].enabled? person` returns true. Whatever logic follows this conditional check is then executed.
|
156
156
|
|
157
157
|
There is no requirement that the thing yielded to the block be a user model or whatever. It can be anything you want, therefore it is a good idea to check that the thing passed into the group block actually responds to what you are trying to do in the `register` proc.
|
158
158
|
|
159
159
|
In your application code, you can do something like this now:
|
160
160
|
|
161
|
-
```
|
162
|
-
if
|
161
|
+
```ruby
|
162
|
+
if Flipper.enabled? :stats, some_admin
|
163
163
|
# do thing...
|
164
164
|
else
|
165
165
|
# do not do thing
|