flipper 0.20.0.beta1 → 0.20.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flipper/adapters/dual_write.rb +67 -0
- data/lib/flipper/adapters/operation_logger.rb +5 -0
- data/lib/flipper/adapters/sync.rb +1 -1
- data/lib/flipper/dsl.rb +8 -0
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/dual_write_spec.rb +71 -0
- data/spec/flipper/adapters/operation_logger_spec.rb +9 -0
- data/spec/flipper_spec.rb +3 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d324a4fa07054c9c189fba3f8baa100e4c4a70ae4618b251c84be77f56e27e54
|
4
|
+
data.tar.gz: 73a1ff5ddfdfbf04f43296fb0dfe67dd0cf2a3ab094d35909462dfa30fc9ba87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ae1cde3eef862c76a40f6166deb59406a5f8a3560829220fd4291c614e4fd8eb91d300ad2eb218f81e433a447e90c6d88fea194ad05d9e27ea5a282bac51dfe
|
7
|
+
data.tar.gz: 33e3c151261a516fc9cf5b8415c57c472f5a5560d6670815f872b71cbf99293c79a1e7f1788e2db6a262f7c3b7e8ec2479717b59cdd6dba2cdc52945d9fc5c1b
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Flipper
|
2
|
+
module Adapters
|
3
|
+
class DualWrite
|
4
|
+
include ::Flipper::Adapter
|
5
|
+
|
6
|
+
# Public: The name of the adapter.
|
7
|
+
attr_reader :name
|
8
|
+
|
9
|
+
# Public: Build a new sync instance.
|
10
|
+
#
|
11
|
+
# local - The local flipper adapter that should serve reads.
|
12
|
+
# remote - The remote flipper adapter that writes should go to first (in
|
13
|
+
# addition to the local adapter).
|
14
|
+
def initialize(local, remote, options = {})
|
15
|
+
@name = :dual_write
|
16
|
+
@local = local
|
17
|
+
@remote = remote
|
18
|
+
end
|
19
|
+
|
20
|
+
def features
|
21
|
+
@local.features
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(feature)
|
25
|
+
@local.get(feature)
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_multi(features)
|
29
|
+
@local.get_multi(features)
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_all
|
33
|
+
@local.get_all
|
34
|
+
end
|
35
|
+
|
36
|
+
def add(feature)
|
37
|
+
result = @remote.add(feature)
|
38
|
+
@local.add(feature)
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
def remove(feature)
|
43
|
+
result = @remote.remove(feature)
|
44
|
+
@local.remove(feature)
|
45
|
+
result
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear(feature)
|
49
|
+
result = @remote.clear(feature)
|
50
|
+
@local.clear(feature)
|
51
|
+
result
|
52
|
+
end
|
53
|
+
|
54
|
+
def enable(feature, gate, thing)
|
55
|
+
result = @remote.enable(feature, gate, thing)
|
56
|
+
@local.enable(feature, gate, thing)
|
57
|
+
result
|
58
|
+
end
|
59
|
+
|
60
|
+
def disable(feature, gate, thing)
|
61
|
+
result = @remote.disable(feature, gate, thing)
|
62
|
+
@local.disable(feature, gate, thing)
|
63
|
+
result
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -117,6 +117,11 @@ module Flipper
|
|
117
117
|
def reset
|
118
118
|
@operations.clear
|
119
119
|
end
|
120
|
+
|
121
|
+
def inspect
|
122
|
+
inspect_id = ::Kernel::format "%x", (object_id * 2)
|
123
|
+
%(#<#{self.class}:0x#{inspect_id} @name=#{name.inspect}, @operations=#{@operations.inspect}, @adapter=#{@adapter.inspect}>)
|
124
|
+
end
|
120
125
|
end
|
121
126
|
end
|
122
127
|
end
|
@@ -17,7 +17,7 @@ module Flipper
|
|
17
17
|
# Public: Build a new sync instance.
|
18
18
|
#
|
19
19
|
# local - The local flipper adapter that should serve reads.
|
20
|
-
# remote - The remote flipper
|
20
|
+
# remote - The remote flipper adapter that should serve writes and update
|
21
21
|
# the local on an interval.
|
22
22
|
# interval - The Float or Integer number of seconds between syncs from
|
23
23
|
# remote to local. Default value is set in IntervalSynchronizer.
|
data/lib/flipper/dsl.rb
CHANGED
@@ -273,5 +273,13 @@ module Flipper
|
|
273
273
|
def import(flipper)
|
274
274
|
adapter.import(flipper.adapter)
|
275
275
|
end
|
276
|
+
|
277
|
+
# Cloud DSL method that does nothing for open source version.
|
278
|
+
def sync
|
279
|
+
end
|
280
|
+
|
281
|
+
# Cloud DSL method that does nothing for open source version.
|
282
|
+
def sync_secret
|
283
|
+
end
|
276
284
|
end
|
277
285
|
end
|
data/lib/flipper/version.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'flipper/adapters/dual_write'
|
3
|
+
require 'flipper/adapters/operation_logger'
|
4
|
+
require 'flipper/spec/shared_adapter_specs'
|
5
|
+
require 'active_support/notifications'
|
6
|
+
|
7
|
+
RSpec.describe Flipper::Adapters::DualWrite do
|
8
|
+
let(:local_adapter) do
|
9
|
+
Flipper::Adapters::OperationLogger.new Flipper::Adapters::Memory.new
|
10
|
+
end
|
11
|
+
let(:remote_adapter) do
|
12
|
+
Flipper::Adapters::OperationLogger.new Flipper::Adapters::Memory.new
|
13
|
+
end
|
14
|
+
let(:local) { Flipper.new(local_adapter) }
|
15
|
+
let(:remote) { Flipper.new(remote_adapter) }
|
16
|
+
let(:sync) { Flipper.new(subject) }
|
17
|
+
|
18
|
+
subject do
|
19
|
+
described_class.new(local_adapter, remote_adapter)
|
20
|
+
end
|
21
|
+
|
22
|
+
it_should_behave_like 'a flipper adapter'
|
23
|
+
|
24
|
+
it 'only uses local for #features' do
|
25
|
+
subject.features
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'only uses local for #get' do
|
29
|
+
subject.get sync[:search]
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'only uses local for #get_multi' do
|
33
|
+
subject.get_multi [sync[:search]]
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'only uses local for #get_all' do
|
37
|
+
subject.get_all
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'updates remote and local for #add' do
|
41
|
+
subject.add sync[:search]
|
42
|
+
expect(remote_adapter.count(:add)).to be(1)
|
43
|
+
expect(local_adapter.count(:add)).to be(1)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'updates remote and local for #remove' do
|
47
|
+
subject.remove sync[:search]
|
48
|
+
expect(remote_adapter.count(:remove)).to be(1)
|
49
|
+
expect(local_adapter.count(:remove)).to be(1)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'updates remote and local for #clear' do
|
53
|
+
subject.clear sync[:search]
|
54
|
+
expect(remote_adapter.count(:clear)).to be(1)
|
55
|
+
expect(local_adapter.count(:clear)).to be(1)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'updates remote and local for #enable' do
|
59
|
+
feature = sync[:search]
|
60
|
+
subject.enable feature, feature.gate(:boolean), local.boolean
|
61
|
+
expect(remote_adapter.count(:enable)).to be(1)
|
62
|
+
expect(local_adapter.count(:enable)).to be(1)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'updates remote and local for #disable' do
|
66
|
+
feature = sync[:search]
|
67
|
+
subject.disable feature, feature.gate(:boolean), local.boolean(false)
|
68
|
+
expect(remote_adapter.count(:disable)).to be(1)
|
69
|
+
expect(local_adapter.count(:disable)).to be(1)
|
70
|
+
end
|
71
|
+
end
|
@@ -11,6 +11,15 @@ RSpec.describe Flipper::Adapters::OperationLogger do
|
|
11
11
|
|
12
12
|
it_should_behave_like 'a flipper adapter'
|
13
13
|
|
14
|
+
it 'shows itself when inspect' do
|
15
|
+
subject.features
|
16
|
+
output = subject.inspect
|
17
|
+
expect(output).to match(/OperationLogger/)
|
18
|
+
expect(output).to match(/operation_logger/)
|
19
|
+
expect(output).to match(/@type=:features/)
|
20
|
+
expect(output).to match(/@adapter=#<Flipper::Adapters::Memory/)
|
21
|
+
end
|
22
|
+
|
14
23
|
it 'forwards missing methods to underlying adapter' do
|
15
24
|
adapter = Class.new do
|
16
25
|
def foo
|
data/spec/flipper_spec.rb
CHANGED
@@ -217,9 +217,9 @@ RSpec.describe Flipper do
|
|
217
217
|
expect(described_class.memoizing?).to eq(described_class.adapter.memoizing?)
|
218
218
|
end
|
219
219
|
|
220
|
-
it 'delegates sync stuff to instance and
|
221
|
-
expect
|
222
|
-
expect
|
220
|
+
it 'delegates sync stuff to instance and does nothing' do
|
221
|
+
expect(described_class.sync).to be(nil)
|
222
|
+
expect(described_class.sync_secret).to be(nil)
|
223
223
|
end
|
224
224
|
|
225
225
|
it 'delegates sync stuff to instance for Flipper::Cloud' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.20.0.
|
4
|
+
version: 0.20.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/flipper.rb
|
56
56
|
- lib/flipper/actor.rb
|
57
57
|
- lib/flipper/adapter.rb
|
58
|
+
- lib/flipper/adapters/dual_write.rb
|
58
59
|
- lib/flipper/adapters/http.rb
|
59
60
|
- lib/flipper/adapters/http/client.rb
|
60
61
|
- lib/flipper/adapters/http/error.rb
|
@@ -104,6 +105,7 @@ files:
|
|
104
105
|
- spec/fixtures/feature.json
|
105
106
|
- spec/flipper/actor_spec.rb
|
106
107
|
- spec/flipper/adapter_spec.rb
|
108
|
+
- spec/flipper/adapters/dual_write_spec.rb
|
107
109
|
- spec/flipper/adapters/http_spec.rb
|
108
110
|
- spec/flipper/adapters/instrumented_spec.rb
|
109
111
|
- spec/flipper/adapters/memoizable_spec.rb
|
@@ -178,6 +180,7 @@ test_files:
|
|
178
180
|
- spec/fixtures/feature.json
|
179
181
|
- spec/flipper/actor_spec.rb
|
180
182
|
- spec/flipper/adapter_spec.rb
|
183
|
+
- spec/flipper/adapters/dual_write_spec.rb
|
181
184
|
- spec/flipper/adapters/http_spec.rb
|
182
185
|
- spec/flipper/adapters/instrumented_spec.rb
|
183
186
|
- spec/flipper/adapters/memoizable_spec.rb
|