flipper-rollout 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/flipper-rollout.gemspec +25 -0
- data/lib/flipper/adapters/rollout.rb +71 -0
- data/lib/flipper/version.rb +3 -0
- data/spec/flipper/adapters/rollout_spec.rb +136 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 706bb76c74fbb139f274e33917f9278407552915
|
4
|
+
data.tar.gz: 4ff9d2384c2ef1cea6a9fea825e7ce7c777f49ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e8cdeb9ea928ea82398e502e584a4888f60b1c87aef28b5f05e6558c9dd26c3a707e975b6e483aa5292d897347629f2c3d59876a2ed7e4e02f7830d7e40b2bd
|
7
|
+
data.tar.gz: 41d1b9753b798196069983b5284cf6288d37c89c379fb9051939cba7560587190f2855bfdca789b8ce59a87bf4834d07de764fad1017f404c9b81402ca8690f6
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/flipper/version', __FILE__)
|
3
|
+
|
4
|
+
flipper_rollout_files = lambda do |file|
|
5
|
+
file =~ /rollout/
|
6
|
+
end
|
7
|
+
|
8
|
+
Gem::Specification.new do |gem|
|
9
|
+
gem.authors = ['John Nunemaker']
|
10
|
+
gem.email = ['nunemaker@gmail.com']
|
11
|
+
gem.summary = 'Rollout adapter for Flipper'
|
12
|
+
gem.description = 'Rollout adapter for Flipper'
|
13
|
+
gem.license = 'MIT'
|
14
|
+
gem.homepage = 'https://github.com/jnunemaker/flipper'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split("\n").select(&flipper_rollout_files) + ['lib/flipper/version.rb']
|
17
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_rollout_files)
|
18
|
+
gem.name = 'flipper-rollout'
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
gem.version = Flipper::VERSION
|
21
|
+
|
22
|
+
gem.add_dependency 'flipper', "~> #{Flipper::VERSION}"
|
23
|
+
gem.add_dependency 'redis', '>= 2.2', '< 4.1.0'
|
24
|
+
gem.add_dependency 'rollout', "~> 2.0"
|
25
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Flipper
|
2
|
+
module Adapters
|
3
|
+
class Rollout
|
4
|
+
class AdapterMethodNotSupportedError < Error
|
5
|
+
def initialize(message = 'unsupported method called for import adapter')
|
6
|
+
super(message)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Public: The name of the adapter.
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
def initialize(rollout)
|
14
|
+
@rollout = rollout
|
15
|
+
@name = :rollout
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: The set of known features.
|
19
|
+
def features
|
20
|
+
@rollout.features
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: Gets the values for all gates for a given feature.
|
24
|
+
#
|
25
|
+
# Returns a Hash of Flipper::Gate#key => value.
|
26
|
+
def get(feature)
|
27
|
+
feature = @rollout.get(feature.key)
|
28
|
+
percentage = feature.percentage.zero? ? nil : feature.percentage
|
29
|
+
{
|
30
|
+
boolean: nil,
|
31
|
+
groups: Set.new(feature.groups),
|
32
|
+
actors: Set.new(feature.users),
|
33
|
+
percentage_of_actors: percentage,
|
34
|
+
percentage_of_time: nil,
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_multi(_features)
|
39
|
+
raise AdapterMethodNotSupportedError
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_all
|
43
|
+
raise AdapterMethodNotSupportedError
|
44
|
+
end
|
45
|
+
|
46
|
+
def add(_feature)
|
47
|
+
raise AdapterMethodNotSupportedError
|
48
|
+
end
|
49
|
+
|
50
|
+
def remove(_feature)
|
51
|
+
raise AdapterMethodNotSupportedError
|
52
|
+
end
|
53
|
+
|
54
|
+
def clear(_feature)
|
55
|
+
raise AdapterMethodNotSupportedError
|
56
|
+
end
|
57
|
+
|
58
|
+
def enable(_feature, _gate, _thing)
|
59
|
+
raise AdapterMethodNotSupportedError
|
60
|
+
end
|
61
|
+
|
62
|
+
def disable(_feature, _gate, _thing)
|
63
|
+
raise AdapterMethodNotSupportedError
|
64
|
+
end
|
65
|
+
|
66
|
+
def import(_source_adapter)
|
67
|
+
raise AdapterMethodNotSupportedError
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'redis'
|
3
|
+
require 'rollout'
|
4
|
+
require 'flipper/adapters/rollout'
|
5
|
+
require 'flipper/adapters/memory'
|
6
|
+
require 'flipper/spec/shared_adapter_specs'
|
7
|
+
|
8
|
+
RSpec.describe Flipper::Adapters::Rollout do
|
9
|
+
let(:redis) { Redis.new }
|
10
|
+
let(:rollout) { Rollout.new(redis) }
|
11
|
+
let(:source_adapter) { described_class.new(rollout) }
|
12
|
+
let(:source_flipper) { Flipper.new(source_adapter) }
|
13
|
+
let(:destination_adapter) { Flipper::Adapters::Memory.new }
|
14
|
+
let(:destination_flipper) { Flipper.new(destination_adapter) }
|
15
|
+
|
16
|
+
before do
|
17
|
+
redis.flushdb
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#name' do
|
21
|
+
it 'has name that is a symbol' do
|
22
|
+
expect(source_adapter.name).not_to be_nil
|
23
|
+
expect(source_adapter.name).to be_instance_of(Symbol)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#get' do
|
28
|
+
it 'returns hash of gate data' do
|
29
|
+
rollout.activate_user(:chat, Struct.new(:id).new(1))
|
30
|
+
rollout.activate_percentage(:chat, 20)
|
31
|
+
rollout.activate_group(:chat, :admins)
|
32
|
+
feature = Struct.new(:key).new(:chat)
|
33
|
+
expected = {
|
34
|
+
actors: Set.new(["1"]),
|
35
|
+
boolean: nil,
|
36
|
+
groups: Set.new([:admins]),
|
37
|
+
percentage_of_actors: 20.0,
|
38
|
+
percentage_of_time: nil,
|
39
|
+
}
|
40
|
+
expect(source_adapter.get(feature)).to eq(expected)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#features' do
|
45
|
+
it 'returns all feature keys' do
|
46
|
+
rollout.activate(:chat)
|
47
|
+
rollout.activate(:messaging)
|
48
|
+
rollout.activate(:push_notifications)
|
49
|
+
expect(source_adapter.features).to match_array([:chat, :messaging, :push_notifications])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'can have one feature imported' do
|
54
|
+
rollout.activate(:search)
|
55
|
+
destination_flipper.import(source_flipper)
|
56
|
+
expect(destination_flipper.features.map(&:key)).to eq(["search"])
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'can have multiple features imported' do
|
60
|
+
rollout.activate(:yep)
|
61
|
+
rollout.activate_group(:preview_features, :developers)
|
62
|
+
rollout.activate_group(:preview_features, :marketers)
|
63
|
+
rollout.activate_group(:preview_features, :company)
|
64
|
+
rollout.activate_group(:preview_features, :early_access)
|
65
|
+
rollout.activate_user(:preview_features, Struct.new(:id).new(1))
|
66
|
+
rollout.activate_user(:preview_features, Struct.new(:id).new(2))
|
67
|
+
rollout.activate_user(:preview_features, Struct.new(:id).new(3))
|
68
|
+
rollout.activate_percentage(:issues_next, 25)
|
69
|
+
|
70
|
+
destination_flipper.import(source_flipper)
|
71
|
+
|
72
|
+
feature = destination_flipper[:yep]
|
73
|
+
expect(feature.boolean_value).to eq(true)
|
74
|
+
|
75
|
+
feature = destination_flipper[:preview_features]
|
76
|
+
expect(feature.boolean_value).to be(false)
|
77
|
+
expect(feature.actors_value).to eq(Set['1', '2', '3'])
|
78
|
+
expected_groups = Set['developers', 'marketers', 'company', 'early_access']
|
79
|
+
expect(feature.groups_value).to eq(expected_groups)
|
80
|
+
expect(feature.percentage_of_actors_value).to be(0)
|
81
|
+
|
82
|
+
feature = destination_flipper[:issues_next]
|
83
|
+
expect(feature.boolean_value).to eq(false)
|
84
|
+
expect(feature.actors_value).to eq(Set.new)
|
85
|
+
expect(feature.groups_value).to eq(Set.new)
|
86
|
+
expect(feature.percentage_of_actors_value).to be(25.0)
|
87
|
+
|
88
|
+
feature = destination_flipper[:verbose_logging]
|
89
|
+
expect(feature.boolean_value).to eq(false)
|
90
|
+
expect(feature.actors_value).to eq(Set.new)
|
91
|
+
expect(feature.groups_value).to eq(Set.new)
|
92
|
+
expect(feature.percentage_of_actors_value).to be(0)
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'unsupported methods' do
|
96
|
+
it 'raises on get_multi' do
|
97
|
+
expect { source_adapter.get_multi([]) }
|
98
|
+
.to raise_error(Flipper::Adapters::Rollout::AdapterMethodNotSupportedError)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'raises on get_all' do
|
102
|
+
expect { source_adapter.get_all }
|
103
|
+
.to raise_error(Flipper::Adapters::Rollout::AdapterMethodNotSupportedError)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'raises on add' do
|
107
|
+
expect { source_adapter.add(:feature) }
|
108
|
+
.to raise_error(Flipper::Adapters::Rollout::AdapterMethodNotSupportedError)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'raises on remove' do
|
112
|
+
expect { source_adapter.remove(:feature) }
|
113
|
+
.to raise_error(Flipper::Adapters::Rollout::AdapterMethodNotSupportedError)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'raises on clear' do
|
117
|
+
expect { source_adapter.clear(:feature) }
|
118
|
+
.to raise_error(Flipper::Adapters::Rollout::AdapterMethodNotSupportedError)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'raises on enable' do
|
122
|
+
expect { source_adapter.enable(:feature, :gate, :thing) }
|
123
|
+
.to raise_error(Flipper::Adapters::Rollout::AdapterMethodNotSupportedError)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'raises on disable' do
|
127
|
+
expect { source_adapter.disable(:feature, :gate, :thing) }
|
128
|
+
.to raise_error(Flipper::Adapters::Rollout::AdapterMethodNotSupportedError)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'raises on import' do
|
132
|
+
expect { source_adapter.import(:source_adapter) }
|
133
|
+
.to raise_error(Flipper::Adapters::Rollout::AdapterMethodNotSupportedError)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flipper-rollout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.12.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Nunemaker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: flipper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.12.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.12.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 4.1.0
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.2'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 4.1.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rollout
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.0'
|
61
|
+
description: Rollout adapter for Flipper
|
62
|
+
email:
|
63
|
+
- nunemaker@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- flipper-rollout.gemspec
|
69
|
+
- lib/flipper/adapters/rollout.rb
|
70
|
+
- lib/flipper/version.rb
|
71
|
+
- spec/flipper/adapters/rollout_spec.rb
|
72
|
+
homepage: https://github.com/jnunemaker/flipper
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.5.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Rollout adapter for Flipper
|
96
|
+
test_files:
|
97
|
+
- spec/flipper/adapters/rollout_spec.rb
|