flipper-rollout 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/rollout/README.md +10 -3
- data/examples/rollout/basic.rb +32 -0
- data/examples/rollout/import.rb +41 -0
- data/lib/flipper/adapters/rollout.rb +27 -6
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/rollout_spec.rb +35 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b1f4a58ee4db5bf368bc0798d572ba2e4bbedac
|
4
|
+
data.tar.gz: 36e940c9d386b504837a9cb7a53bca4f856f1219
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4999b9d3c43560c15a72632b9fa5ebc86a50c91448e5f12d804debf1aeed3cedaf3291d483205cfaa2f3c2144257534bb6051da4e01ddc79137d488427b9ce4
|
7
|
+
data.tar.gz: c2907694644a3b06cc5bb83d873d0470c5464adaecbdb07407eeb26ced32988e4dfdbccad48c61130df2826e6bb5d0bfd9fc8c096a8ba3c96777366369e0a595
|
data/docs/rollout/README.md
CHANGED
@@ -23,18 +23,25 @@ Or install it yourself with:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
Assuming you've configured a [default Flipper instance](https://github.com/jnunemaker/flipper#user-content-examples)
|
27
|
-
|
28
26
|
```ruby
|
29
27
|
require 'redis'
|
28
|
+
require 'rollout'
|
29
|
+
require 'flipper'
|
30
|
+
require 'flipper/adapters/redis'
|
30
31
|
require 'flipper/adapters/rollout'
|
31
32
|
|
33
|
+
# setup redis, rollout and rollout flipper
|
32
34
|
redis = Redis.new
|
33
35
|
rollout = Rollout.new(redis)
|
34
|
-
|
35
36
|
rollout_adapter = Flipper::Adapters::Rollout.new(rollout)
|
36
37
|
rollout_flipper = Flipper.new(rollout_adapter)
|
37
38
|
|
39
|
+
# setup flipper default instance
|
40
|
+
Flipper.configure do |config|
|
41
|
+
config.default { Flipper.new(Flipper::Adapters::Redis.new(redis)) }
|
42
|
+
end
|
43
|
+
|
44
|
+
# import rollout into redis flipper
|
38
45
|
Flipper.import(rollout_flipper)
|
39
46
|
```
|
40
47
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
root_path = Pathname(__FILE__).dirname.join('..').expand_path
|
5
|
+
lib_path = root_path.join('lib')
|
6
|
+
$:.unshift(lib_path)
|
7
|
+
|
8
|
+
require 'redis'
|
9
|
+
require 'rollout'
|
10
|
+
require 'flipper'
|
11
|
+
require 'flipper/adapters/rollout'
|
12
|
+
|
13
|
+
redis = Redis.new
|
14
|
+
rollout = Rollout.new(redis)
|
15
|
+
rollout.activate(:stats)
|
16
|
+
|
17
|
+
adapter = Flipper::Adapters::Rollout.new(rollout)
|
18
|
+
flipper = Flipper.new(adapter)
|
19
|
+
|
20
|
+
if flipper[:stats].enabled?
|
21
|
+
puts "Enabled!"
|
22
|
+
else
|
23
|
+
puts "Disabled!"
|
24
|
+
end
|
25
|
+
|
26
|
+
rollout.deactivate(:stats)
|
27
|
+
|
28
|
+
if flipper[:stats].enabled?
|
29
|
+
puts "Enabled!"
|
30
|
+
else
|
31
|
+
puts "Disabled!"
|
32
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
root_path = Pathname(__FILE__).dirname.join('..').expand_path
|
5
|
+
lib_path = root_path.join('lib')
|
6
|
+
$:.unshift(lib_path)
|
7
|
+
|
8
|
+
require 'redis'
|
9
|
+
require 'rollout'
|
10
|
+
require 'flipper'
|
11
|
+
require 'flipper/adapters/redis'
|
12
|
+
require 'flipper/adapters/rollout'
|
13
|
+
|
14
|
+
# setup redis, rollout and rollout flipper
|
15
|
+
redis = Redis.new
|
16
|
+
rollout = Rollout.new(redis)
|
17
|
+
rollout_adapter = Flipper::Adapters::Rollout.new(rollout)
|
18
|
+
rollout_flipper = Flipper.new(rollout_adapter)
|
19
|
+
|
20
|
+
# setup flipper default instance
|
21
|
+
Flipper.configure do |config|
|
22
|
+
config.default do
|
23
|
+
Flipper.new(Flipper::Adapters::Redis.new(redis))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# flush redis so we have clean state for script
|
28
|
+
redis.flushdb
|
29
|
+
|
30
|
+
# activate some rollout stuff to show that importing works
|
31
|
+
rollout.activate(:stats)
|
32
|
+
rollout.activate_user(:search, Struct.new(:id).new(1))
|
33
|
+
rollout.activate_group(:admin, :admins)
|
34
|
+
|
35
|
+
# import rollout into redis flipper
|
36
|
+
Flipper.import(rollout_flipper)
|
37
|
+
|
38
|
+
# demonstrate that the rollout enablements made it into flipper
|
39
|
+
p Flipper[:stats].boolean_value # true
|
40
|
+
p Flipper[:search].actors_value # #<Set: {"1"}>
|
41
|
+
p Flipper[:admin].groups_value # #<Set: {"admins"}>
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require "flipper/errors"
|
2
|
+
|
1
3
|
module Flipper
|
2
4
|
module Adapters
|
3
5
|
class Rollout
|
6
|
+
include Adapter
|
7
|
+
|
4
8
|
class AdapterMethodNotSupportedError < Error
|
5
9
|
def initialize(message = 'unsupported method called for import adapter')
|
6
10
|
super(message)
|
@@ -24,13 +28,30 @@ module Flipper
|
|
24
28
|
#
|
25
29
|
# Returns a Hash of Flipper::Gate#key => value.
|
26
30
|
def get(feature)
|
27
|
-
|
28
|
-
|
31
|
+
rollout_feature = @rollout.get(feature.key)
|
32
|
+
return default_config if rollout_feature.nil?
|
33
|
+
|
34
|
+
boolean = nil
|
35
|
+
groups = Set.new(rollout_feature.groups)
|
36
|
+
actors = Set.new(rollout_feature.users)
|
37
|
+
|
38
|
+
percentage_of_actors = case rollout_feature.percentage
|
39
|
+
when 100
|
40
|
+
boolean = true
|
41
|
+
groups = Set.new
|
42
|
+
actors = Set.new
|
43
|
+
nil
|
44
|
+
when 0
|
45
|
+
nil
|
46
|
+
else
|
47
|
+
rollout_feature.percentage
|
48
|
+
end
|
49
|
+
|
29
50
|
{
|
30
|
-
boolean:
|
31
|
-
groups:
|
32
|
-
actors:
|
33
|
-
percentage_of_actors:
|
51
|
+
boolean: boolean,
|
52
|
+
groups: groups,
|
53
|
+
actors: actors,
|
54
|
+
percentage_of_actors: percentage_of_actors,
|
34
55
|
percentage_of_time: nil,
|
35
56
|
}
|
36
57
|
end
|
data/lib/flipper/version.rb
CHANGED
@@ -29,16 +29,49 @@ RSpec.describe Flipper::Adapters::Rollout do
|
|
29
29
|
rollout.activate_user(:chat, Struct.new(:id).new(1))
|
30
30
|
rollout.activate_percentage(:chat, 20)
|
31
31
|
rollout.activate_group(:chat, :admins)
|
32
|
-
feature =
|
32
|
+
feature = source_flipper[:chat]
|
33
33
|
expected = {
|
34
|
-
actors: Set.new(["1"]),
|
35
34
|
boolean: nil,
|
36
35
|
groups: Set.new([:admins]),
|
36
|
+
actors: Set.new(["1"]),
|
37
37
|
percentage_of_actors: 20.0,
|
38
38
|
percentage_of_time: nil,
|
39
39
|
}
|
40
40
|
expect(source_adapter.get(feature)).to eq(expected)
|
41
41
|
end
|
42
|
+
|
43
|
+
it 'returns fully flipper enabled for fully rollout activated' do
|
44
|
+
rollout.activate(:chat)
|
45
|
+
feature = source_flipper[:chat]
|
46
|
+
expected = {
|
47
|
+
boolean: true,
|
48
|
+
groups: Set.new,
|
49
|
+
actors: Set.new,
|
50
|
+
percentage_of_actors: nil,
|
51
|
+
percentage_of_time: nil,
|
52
|
+
}
|
53
|
+
expect(source_adapter.get(feature)).to eq(expected)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns fully flipper enabled for fully rollout activated with user/group' do
|
57
|
+
rollout.activate_user(:chat, Struct.new(:id).new(1))
|
58
|
+
rollout.activate_group(:chat, :admins)
|
59
|
+
rollout.activate(:chat)
|
60
|
+
feature = source_flipper[:chat]
|
61
|
+
expected = {
|
62
|
+
boolean: true,
|
63
|
+
groups: Set.new,
|
64
|
+
actors: Set.new,
|
65
|
+
percentage_of_actors: nil,
|
66
|
+
percentage_of_time: nil,
|
67
|
+
}
|
68
|
+
expect(source_adapter.get(feature)).to eq(expected)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns default hash of gate data for feature not existing in rollout' do
|
72
|
+
feature = source_flipper[:chat]
|
73
|
+
expect(source_adapter.get(feature)).to eq(source_adapter.default_config)
|
74
|
+
end
|
42
75
|
end
|
43
76
|
|
44
77
|
describe '#features' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-rollout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flipper
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.12.
|
19
|
+
version: 0.12.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.12.
|
26
|
+
version: 0.12.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: redis
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,8 @@ extensions: []
|
|
66
66
|
extra_rdoc_files: []
|
67
67
|
files:
|
68
68
|
- docs/rollout/README.md
|
69
|
+
- examples/rollout/basic.rb
|
70
|
+
- examples/rollout/import.rb
|
69
71
|
- flipper-rollout.gemspec
|
70
72
|
- lib/flipper/adapters/rollout.rb
|
71
73
|
- lib/flipper/version.rb
|