flipper 0.11.0.beta5 → 0.11.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +6 -1
- data/docs/Adapters.md +5 -5
- data/lib/flipper/adapters/cache_store.rb +104 -0
- data/lib/flipper/middleware/setup_env.rb +3 -3
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/cache_store_spec.rb +50 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc657f1ced7ca41760051223843e487c3c820277
|
4
|
+
data.tar.gz: '0520502010855501979601516821cac277ce3891'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9afe59c11ad41ec976ed8cb804929985afdb9e737146d9639510c75298ee88f1fb1573d92580f3504840a453e3cf84ed1a4b9d9c61ad5975fc1471d8096d34f
|
7
|
+
data.tar.gz: a1c682c40e47feb582e74069aad67f261b9a2cb14b3cd0978a175a305e6fd31a062804514608c60dffe743a635d4037b7aba55a6410b12a68eaef8a9343506a1
|
data/Changelog.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
* * Set flipper from env for API and UI (https://github.com/jnunemaker/flipper/pull/223 and https://github.com/jnunemaker/flipper/pull/229). It is documented, but now the memoizing middleware requires that the SetupEnv middleware is used first.
|
6
6
|
* Drop support for Ruby 2.0 as it is end of lined (https://github.com/jnunemaker/flipper/commit/c2c81ed89938155ce91acb5173ac38580f630e3d).
|
7
|
-
* Allow unregistered groups (https://github.com/jnunemaker/flipper/pull/244). Only break in
|
7
|
+
* Allow unregistered groups (https://github.com/jnunemaker/flipper/pull/244). Only break in compatibility is that previously unregistered groups could not be enabled and now they can be.
|
8
8
|
|
9
9
|
### Additions/Changes
|
10
10
|
|
@@ -18,6 +18,11 @@
|
|
18
18
|
* Made it possible to instrument Flipper::Cloud (https://github.com/jnunemaker/flipper/commit/4b10e4d807772202f63881f5e2c00d11ac58481f).
|
19
19
|
* Made it possible to wrap Http adapter when using Flipper::Cloud (https://github.com/jnunemaker/flipper/commit/4b10e4d807772202f63881f5e2c00d11ac58481f).
|
20
20
|
* Instrument get_multi in instrumented adapter (https://github.com/jnunemaker/flipper/commit/951d25c5ce07d3b56b0b2337adf5f6bcbe4050e7).
|
21
|
+
* Allow instrumenting Flipper::Cloud http adapter (https://github.com/jnunemaker/flipper/pull/253).
|
22
|
+
* Add DSL#preload_all and Adapter#get_all to allow for making even more efficient loading of features (https://github.com/jnunemaker/flipper/pull/255).
|
23
|
+
* Allow setting debug output of http adapter (https://github.com/jnunemaker/flipper/pull/256 and https://github.com/jnunemaker/flipper/pull/258).
|
24
|
+
* Allow setting env key for middleware (https://github.com/jnunemaker/flipper/pull/259).
|
25
|
+
* Added ActiveSupport cache store adapter for use with Rails.cache (https://github.com/jnunemaker/flipper/pull/265).
|
21
26
|
|
22
27
|
## 0.10.2
|
23
28
|
|
data/docs/Adapters.md
CHANGED
@@ -4,15 +4,15 @@ 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 3, 4, and 5.
|
8
|
+
* [Cassanity adapter](https://github.com/jnunemaker/flipper-cassanity)
|
9
|
+
* [Http adapter](https://github.com/jnunemaker/flipper/blob/master/docs/http)
|
7
10
|
* [memory adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/memory.rb) – great for tests
|
8
|
-
* [PStore adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/pstore.rb) – great for when a local file is enough
|
9
11
|
* [Mongo adapter](https://github.com/jnunemaker/flipper/blob/master/docs/mongo)
|
12
|
+
* [PStore adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/pstore.rb) – great for when a local file is enough
|
13
|
+
* [read-only adapter](https://github.com/jnunemaker/flipper/blob/master/docs/read-only)
|
10
14
|
* [Redis adapter](https://github.com/jnunemaker/flipper/blob/master/docs/redis)
|
11
|
-
* [ActiveRecord adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_record) - Rails 3, 4, and 5.
|
12
15
|
* [Sequel adapter](https://github.com/jnunemaker/flipper/blob/master/docs/sequel)
|
13
|
-
* [Cassanity adapter](https://github.com/jnunemaker/flipper-cassanity)
|
14
|
-
* [read-only adapter](https://github.com/jnunemaker/flipper/blob/master/docs/read-only)
|
15
|
-
* [Http adapter](https://github.com/jnunemaker/flipper/blob/master/docs/http)
|
16
16
|
|
17
17
|
## Community Supported
|
18
18
|
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Flipper
|
2
|
+
module Adapters
|
3
|
+
# Public: Adapter that wraps another adapter with the ability to cache
|
4
|
+
# adapter calls in ActiveSupport::CacheStore caches.
|
5
|
+
#
|
6
|
+
class CacheStore
|
7
|
+
include ::Flipper::Adapter
|
8
|
+
|
9
|
+
Version = 'v1'.freeze
|
10
|
+
Namespace = "flipper/#{Version}".freeze
|
11
|
+
FeaturesKey = "#{Namespace}/features".freeze
|
12
|
+
|
13
|
+
# Private
|
14
|
+
def self.key_for(key)
|
15
|
+
"#{Namespace}/feature/#{key}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Internal
|
19
|
+
attr_reader :cache
|
20
|
+
|
21
|
+
# Public: The name of the adapter.
|
22
|
+
attr_reader :name
|
23
|
+
|
24
|
+
# Public
|
25
|
+
def initialize(adapter, cache, expires_in: nil)
|
26
|
+
@adapter = adapter
|
27
|
+
@name = :cache_store
|
28
|
+
@cache = cache
|
29
|
+
@write_options = {}
|
30
|
+
@write_options.merge!(expires_in: expires_in) if expires_in
|
31
|
+
end
|
32
|
+
|
33
|
+
# Public
|
34
|
+
def features
|
35
|
+
@cache.fetch(FeaturesKey, @write_options) do
|
36
|
+
@adapter.features
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Public
|
41
|
+
def add(feature)
|
42
|
+
result = @adapter.add(feature)
|
43
|
+
@cache.delete(FeaturesKey)
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
## Public
|
48
|
+
def remove(feature)
|
49
|
+
result = @adapter.remove(feature)
|
50
|
+
@cache.delete(FeaturesKey)
|
51
|
+
@cache.delete(key_for(feature.key))
|
52
|
+
result
|
53
|
+
end
|
54
|
+
|
55
|
+
## Public
|
56
|
+
def clear(feature)
|
57
|
+
result = @adapter.clear(feature)
|
58
|
+
@cache.delete(key_for(feature.key))
|
59
|
+
result
|
60
|
+
end
|
61
|
+
|
62
|
+
## Public
|
63
|
+
def get(feature)
|
64
|
+
@cache.fetch(key_for(feature.key), @write_options) do
|
65
|
+
@adapter.get(feature)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_multi(features)
|
70
|
+
keys = features.map { |feature| key_for(feature.key) }
|
71
|
+
result = @cache.read_multi(keys)
|
72
|
+
uncached_features = features.reject { |feature| result[feature.key] }
|
73
|
+
if uncached_features.any?
|
74
|
+
response = @adapter.get_multi(uncached_features)
|
75
|
+
response.each do |key, value|
|
76
|
+
@cache.write(key_for(key), value, @write_options)
|
77
|
+
result[key] = value
|
78
|
+
end
|
79
|
+
end
|
80
|
+
result
|
81
|
+
end
|
82
|
+
|
83
|
+
## Public
|
84
|
+
def enable(feature, gate, thing)
|
85
|
+
result = @adapter.enable(feature, gate, thing)
|
86
|
+
@cache.delete(key_for(feature.key))
|
87
|
+
result
|
88
|
+
end
|
89
|
+
|
90
|
+
## Public
|
91
|
+
def disable(feature, gate, thing)
|
92
|
+
result = @adapter.disable(feature, gate, thing)
|
93
|
+
@cache.delete(key_for(feature.key))
|
94
|
+
result
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def key_for(key)
|
100
|
+
self.class.key_for(key)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Flipper
|
2
2
|
module Middleware
|
3
3
|
class SetupEnv
|
4
|
-
# Public: Initializes an instance of the
|
4
|
+
# Public: Initializes an instance of the SetupEnv middleware. Allows for
|
5
5
|
# lazy initialization of the flipper instance being set in the env by
|
6
6
|
# providing a block.
|
7
7
|
#
|
@@ -14,10 +14,10 @@ module Flipper
|
|
14
14
|
# flipper = Flipper.new(...)
|
15
15
|
#
|
16
16
|
# # using with a normal flipper instance
|
17
|
-
# use Flipper::Middleware::
|
17
|
+
# use Flipper::Middleware::SetupEnv, flipper
|
18
18
|
#
|
19
19
|
# # using with a block that yields a flipper instance
|
20
|
-
# use Flipper::Middleware::
|
20
|
+
# use Flipper::Middleware::SetupEnv, lambda { Flipper.new(...) }
|
21
21
|
#
|
22
22
|
def initialize(app, flipper_or_block, options = {})
|
23
23
|
@app = app
|
data/lib/flipper/version.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'active_support/cache'
|
3
|
+
require 'flipper/adapters/memory'
|
4
|
+
require 'flipper/adapters/cache_store'
|
5
|
+
require 'flipper/spec/shared_adapter_specs'
|
6
|
+
|
7
|
+
RSpec.describe Flipper::Adapters::CacheStore do
|
8
|
+
let(:memory_adapter) { Flipper::Adapters::Memory.new }
|
9
|
+
let(:cache) { ActiveSupport::Cache::MemoryStore.new }
|
10
|
+
let(:adapter) { described_class.new(memory_adapter, cache) }
|
11
|
+
let(:flipper) { Flipper.new(adapter) }
|
12
|
+
|
13
|
+
subject { adapter }
|
14
|
+
|
15
|
+
it_should_behave_like 'a flipper adapter'
|
16
|
+
|
17
|
+
describe '#remove' do
|
18
|
+
it 'expires feature' do
|
19
|
+
feature = flipper[:stats]
|
20
|
+
adapter.get(feature)
|
21
|
+
adapter.remove(feature)
|
22
|
+
expect(cache.read(described_class.key_for(feature))).to be(nil)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#get_multi' do
|
27
|
+
it 'warms uncached features' do
|
28
|
+
stats = flipper[:stats]
|
29
|
+
search = flipper[:search]
|
30
|
+
other = flipper[:other]
|
31
|
+
stats.enable
|
32
|
+
search.enable
|
33
|
+
|
34
|
+
adapter.get(stats)
|
35
|
+
expect(cache.read(described_class.key_for(search))).to be(nil)
|
36
|
+
expect(cache.read(described_class.key_for(other))).to be(nil)
|
37
|
+
|
38
|
+
adapter.get_multi([stats, search, other])
|
39
|
+
|
40
|
+
expect(cache.read(described_class.key_for(search))[:boolean]).to eq('true')
|
41
|
+
expect(cache.read(described_class.key_for(other))[:boolean]).to be(nil)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#name' do
|
46
|
+
it 'is cache_store' do
|
47
|
+
expect(subject.name).to be(:cache_store)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
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.11.0.
|
4
|
+
version: 0.11.0.beta6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Feature flipper is the act of enabling/disabling features in your application,
|
14
14
|
ideally without re-deploying or changing anything in your code base. Flipper makes
|
@@ -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/cache_store.rb
|
58
59
|
- lib/flipper/adapters/http.rb
|
59
60
|
- lib/flipper/adapters/http/client.rb
|
60
61
|
- lib/flipper/adapters/http/error.rb
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- spec/fixtures/feature.json
|
101
102
|
- spec/flipper/actor_spec.rb
|
102
103
|
- spec/flipper/adapter_spec.rb
|
104
|
+
- spec/flipper/adapters/cache_store_spec.rb
|
103
105
|
- spec/flipper/adapters/http_spec.rb
|
104
106
|
- spec/flipper/adapters/instrumented_spec.rb
|
105
107
|
- spec/flipper/adapters/memoizable_spec.rb
|
@@ -169,6 +171,7 @@ test_files:
|
|
169
171
|
- spec/fixtures/feature.json
|
170
172
|
- spec/flipper/actor_spec.rb
|
171
173
|
- spec/flipper/adapter_spec.rb
|
174
|
+
- spec/flipper/adapters/cache_store_spec.rb
|
172
175
|
- spec/flipper/adapters/http_spec.rb
|
173
176
|
- spec/flipper/adapters/instrumented_spec.rb
|
174
177
|
- spec/flipper/adapters/memoizable_spec.rb
|