flipper-mongo 1.4.2 → 1.5.0.rc2
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/lib/flipper/adapters/mongo.rb +38 -2
- data/lib/flipper/version.rb +1 -1
- metadata +5 -10
- data/examples/mongo/basic.rb +0 -21
- data/examples/mongo/internals.rb +0 -46
- data/flipper-mongo.gemspec +0 -25
- data/spec/flipper/adapters/mongo_spec.rb +0 -38
- data/test/adapters/mongo_test.rb +0 -25
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 58a35a490084d52e5b197334e049019e60bd2928d66b62a7d8bd4d18d7d994ee
|
|
4
|
+
data.tar.gz: 5e931bab140c6d37449bf617a033bce410d65c1129530425d07b92ec4c3c0985
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bd038a61a4b2d548e13f77157769146d86ad0edfb9a5235d892dc8d906d3f647a85e6d175d4ead432fa8df62c59b3c1ddb9da76f3ca9ceb56610426ce4ee411a
|
|
7
|
+
data.tar.gz: fb45e59179beb27ddeb26775134816e522b22e5bc20ce83233236963835524a2f3dd4a9723fe586d582751e9e3c7e28226977d3fc164644ebdb4ce43f496be62
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'set'
|
|
2
2
|
require 'flipper'
|
|
3
3
|
require 'mongo'
|
|
4
|
+
require 'concurrent/map'
|
|
4
5
|
|
|
5
6
|
module Flipper
|
|
6
7
|
module Adapters
|
|
@@ -20,8 +21,20 @@ module Flipper
|
|
|
20
21
|
read_feature_keys
|
|
21
22
|
end
|
|
22
23
|
|
|
24
|
+
# Public: The Flipper::SyncVersion of the flags last synced into this
|
|
25
|
+
# adapter, shared by every process using the same collection.
|
|
26
|
+
def sync_version
|
|
27
|
+
SyncVersion.parse(find(SyncVersion::KEY)['value'])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Public: Records the Flipper::SyncVersion of the flags just synced.
|
|
31
|
+
def sync_version=(version)
|
|
32
|
+
update SyncVersion::KEY, '$set' => { 'value' => version.to_s }
|
|
33
|
+
end
|
|
34
|
+
|
|
23
35
|
# Public: Adds a feature to the set of known features.
|
|
24
36
|
def add(feature)
|
|
37
|
+
ensure_not_reserved_key!(feature)
|
|
25
38
|
update @features_key, '$addToSet' => { 'features' => feature.key }
|
|
26
39
|
true
|
|
27
40
|
end
|
|
@@ -29,12 +42,14 @@ module Flipper
|
|
|
29
42
|
# Public: Removes a feature from the set of known features.
|
|
30
43
|
def remove(feature)
|
|
31
44
|
update @features_key, '$pull' => { 'features' => feature.key }
|
|
32
|
-
|
|
45
|
+
# Removing a reserved name left in the list must not delete the list.
|
|
46
|
+
clear feature unless reserved_key?(feature)
|
|
33
47
|
true
|
|
34
48
|
end
|
|
35
49
|
|
|
36
50
|
# Public: Clears all the gate values for a feature.
|
|
37
51
|
def clear(feature)
|
|
52
|
+
ensure_not_reserved_key!(feature)
|
|
38
53
|
delete feature.key
|
|
39
54
|
true
|
|
40
55
|
end
|
|
@@ -64,6 +79,7 @@ module Flipper
|
|
|
64
79
|
#
|
|
65
80
|
# Returns true.
|
|
66
81
|
def enable(feature, gate, thing)
|
|
82
|
+
ensure_not_reserved_key!(feature)
|
|
67
83
|
case gate.data_type
|
|
68
84
|
when :boolean
|
|
69
85
|
clear(feature)
|
|
@@ -97,6 +113,7 @@ module Flipper
|
|
|
97
113
|
#
|
|
98
114
|
# Returns true.
|
|
99
115
|
def disable(feature, gate, thing)
|
|
116
|
+
ensure_not_reserved_key!(feature)
|
|
100
117
|
case gate.data_type
|
|
101
118
|
when :boolean
|
|
102
119
|
delete feature.key
|
|
@@ -121,6 +138,20 @@ module Flipper
|
|
|
121
138
|
|
|
122
139
|
private
|
|
123
140
|
|
|
141
|
+
# Private: The feature list and sync version live in documents next to
|
|
142
|
+
# the feature documents, so a feature with the same key would overwrite
|
|
143
|
+
# or delete them.
|
|
144
|
+
def reserved_key?(feature)
|
|
145
|
+
Flipper.reserved_key?(feature.key) || feature.key == @features_key.to_s
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def ensure_not_reserved_key!(feature)
|
|
149
|
+
super
|
|
150
|
+
return unless feature.key == @features_key.to_s
|
|
151
|
+
|
|
152
|
+
raise ArgumentError, "#{feature.key.inspect} is reserved by the Mongo adapter and cannot be used as a feature name"
|
|
153
|
+
end
|
|
154
|
+
|
|
124
155
|
def read_feature_keys
|
|
125
156
|
find(@features_key).fetch('features') { Set.new }.to_set
|
|
126
157
|
end
|
|
@@ -187,6 +218,10 @@ module Flipper
|
|
|
187
218
|
end
|
|
188
219
|
|
|
189
220
|
Flipper.configure do |config|
|
|
221
|
+
# Each thread builds its own adapter. Mongo::Client is thread safe and pooled,
|
|
222
|
+
# so share one per process instead of leaving one open for every thread.
|
|
223
|
+
clients = Concurrent::Map.new
|
|
224
|
+
|
|
190
225
|
config.adapter do
|
|
191
226
|
url = ENV["FLIPPER_MONGO_URL"] || ENV["MONGO_URL"]
|
|
192
227
|
collection = ENV["FLIPPER_MONGO_COLLECTION"] || "flipper"
|
|
@@ -195,6 +230,7 @@ Flipper.configure do |config|
|
|
|
195
230
|
raise ArgumentError, "The MONGO_URL environment variable must be set. For example: mongodb://127.0.0.1:27017/flipper"
|
|
196
231
|
end
|
|
197
232
|
|
|
198
|
-
|
|
233
|
+
client = clients.compute_if_absent([Process.pid, url]) { Mongo::Client.new(url) }
|
|
234
|
+
Flipper::Adapters::Mongo.new(client[collection])
|
|
199
235
|
end
|
|
200
236
|
end
|
data/lib/flipper/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flipper-mongo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.0.rc2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Nunemaker
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-24 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: 1.
|
|
19
|
+
version: 1.5.0.rc2
|
|
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: 1.
|
|
26
|
+
version: 1.5.0.rc2
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: mongo
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -44,14 +44,9 @@ executables: []
|
|
|
44
44
|
extensions: []
|
|
45
45
|
extra_rdoc_files: []
|
|
46
46
|
files:
|
|
47
|
-
- examples/mongo/basic.rb
|
|
48
|
-
- examples/mongo/internals.rb
|
|
49
|
-
- flipper-mongo.gemspec
|
|
50
47
|
- lib/flipper-mongo.rb
|
|
51
48
|
- lib/flipper/adapters/mongo.rb
|
|
52
49
|
- lib/flipper/version.rb
|
|
53
|
-
- spec/flipper/adapters/mongo_spec.rb
|
|
54
|
-
- test/adapters/mongo_test.rb
|
|
55
50
|
homepage: https://www.flippercloud.io/docs/adapters/mongo
|
|
56
51
|
licenses:
|
|
57
52
|
- MIT
|
|
@@ -60,7 +55,7 @@ metadata:
|
|
|
60
55
|
homepage_uri: https://www.flippercloud.io
|
|
61
56
|
source_code_uri: https://github.com/flippercloud/flipper
|
|
62
57
|
bug_tracker_uri: https://github.com/flippercloud/flipper/issues
|
|
63
|
-
changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.
|
|
58
|
+
changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.5.0.rc2
|
|
64
59
|
funding_uri: https://github.com/sponsors/flippercloud
|
|
65
60
|
post_install_message:
|
|
66
61
|
rdoc_options: []
|
data/examples/mongo/basic.rb
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'logger'
|
|
3
|
-
|
|
4
|
-
ENV["FLIPPER_MONGO_URL"] ||= "mongodb://127.0.0.1:#{ENV["MONGODB_PORT"] || 27017}"
|
|
5
|
-
require 'flipper/adapters/mongo'
|
|
6
|
-
|
|
7
|
-
Flipper[:stats].enable
|
|
8
|
-
|
|
9
|
-
if Flipper[:stats].enabled?
|
|
10
|
-
puts "Enabled!"
|
|
11
|
-
else
|
|
12
|
-
puts "Disabled!"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
Flipper[:stats].disable
|
|
16
|
-
|
|
17
|
-
if Flipper[:stats].enabled?
|
|
18
|
-
puts "Enabled!"
|
|
19
|
-
else
|
|
20
|
-
puts "Disabled!"
|
|
21
|
-
end
|
data/examples/mongo/internals.rb
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'bundler/setup'
|
|
2
|
-
require 'pp'
|
|
3
|
-
require 'logger'
|
|
4
|
-
|
|
5
|
-
ENV["FLIPPER_MONGO_URL"] ||= "mongodb://127.0.0.1:#{ENV["MONGODB_PORT"] || 27017}"
|
|
6
|
-
require 'flipper/adapters/mongo'
|
|
7
|
-
|
|
8
|
-
# Register a few groups.
|
|
9
|
-
Flipper.register(:admins) { |actor| actor.admin? }
|
|
10
|
-
Flipper.register(:early_access) { |actor| actor.early_access? }
|
|
11
|
-
|
|
12
|
-
# Create a user class that has flipper_id instance method.
|
|
13
|
-
User = Struct.new(:flipper_id)
|
|
14
|
-
|
|
15
|
-
Flipper[:stats].enable
|
|
16
|
-
Flipper[:stats].enable_group :admins
|
|
17
|
-
Flipper[:stats].enable_group :early_access
|
|
18
|
-
Flipper[:stats].enable_actor User.new('25')
|
|
19
|
-
Flipper[:stats].enable_actor User.new('90')
|
|
20
|
-
Flipper[:stats].enable_actor User.new('180')
|
|
21
|
-
Flipper[:stats].enable_percentage_of_time 15
|
|
22
|
-
Flipper[:stats].enable_percentage_of_actors 45
|
|
23
|
-
|
|
24
|
-
Flipper[:search].enable
|
|
25
|
-
|
|
26
|
-
puts 'all docs in collection'
|
|
27
|
-
pp Flipper.adapter.adapter.collection.find.to_a
|
|
28
|
-
# all docs in collection
|
|
29
|
-
# [{"_id"=>"stats",
|
|
30
|
-
# "actors"=>["25", "90", "180"],
|
|
31
|
-
# "boolean"=>"true",
|
|
32
|
-
# "groups"=>["admins", "early_access"],
|
|
33
|
-
# "percentage_of_actors"=>"45",
|
|
34
|
-
# "percentage_of_time"=>"15"},
|
|
35
|
-
# {"_id"=>"flipper_features", "features"=>["stats", "search"]},
|
|
36
|
-
# {"_id"=>"search", "boolean"=>"true"}]
|
|
37
|
-
puts
|
|
38
|
-
|
|
39
|
-
puts 'flipper get of feature'
|
|
40
|
-
pp Flipper.adapter.get(Flipper[:stats])
|
|
41
|
-
# flipper get of feature
|
|
42
|
-
# {:boolean=>"true",
|
|
43
|
-
# :groups=>#<Set: {"admins", "early_access"}>,
|
|
44
|
-
# :actors=>#<Set: {"25", "90", "180"}>,
|
|
45
|
-
# :percentage_of_actors=>"45",
|
|
46
|
-
# :percentage_of_time=>"15"}
|
data/flipper-mongo.gemspec
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
require File.expand_path('../lib/flipper/version', __FILE__)
|
|
3
|
-
require File.expand_path('../lib/flipper/metadata', __FILE__)
|
|
4
|
-
|
|
5
|
-
flipper_mongo_files = lambda do |file|
|
|
6
|
-
file =~ /mongo/
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
Gem::Specification.new do |gem|
|
|
10
|
-
gem.authors = ['John Nunemaker']
|
|
11
|
-
gem.email = 'support@flippercloud.io'
|
|
12
|
-
gem.summary = 'Mongo feature flag adapter for Flipper'
|
|
13
|
-
gem.license = 'MIT'
|
|
14
|
-
gem.homepage = 'https://www.flippercloud.io/docs/adapters/mongo'
|
|
15
|
-
|
|
16
|
-
gem.files = `git ls-files`.split("\n").select(&flipper_mongo_files) + ['lib/flipper/version.rb']
|
|
17
|
-
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_mongo_files)
|
|
18
|
-
gem.name = 'flipper-mongo'
|
|
19
|
-
gem.require_paths = ['lib']
|
|
20
|
-
gem.version = Flipper::VERSION
|
|
21
|
-
gem.metadata = Flipper::METADATA
|
|
22
|
-
|
|
23
|
-
gem.add_dependency 'flipper', "~> #{Flipper::VERSION}"
|
|
24
|
-
gem.add_dependency 'mongo', '~> 2.0'
|
|
25
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require 'flipper/adapters/mongo'
|
|
2
|
-
|
|
3
|
-
Mongo::Logger.logger.level = Logger::INFO
|
|
4
|
-
|
|
5
|
-
RSpec.describe Flipper::Adapters::Mongo do
|
|
6
|
-
subject { described_class.new(collection) }
|
|
7
|
-
|
|
8
|
-
let(:host) { ENV['MONGODB_HOST'] || '127.0.0.1' }
|
|
9
|
-
let(:port) { ENV['MONGODB_PORT'] || 27017 }
|
|
10
|
-
|
|
11
|
-
let(:client) do
|
|
12
|
-
logger = Logger.new('/dev/null')
|
|
13
|
-
Mongo::Client.new(["#{host}:#{port}"], server_selection_timeout: 0.01, database: 'testing', logger: logger)
|
|
14
|
-
end
|
|
15
|
-
let(:collection) { client['testing'] }
|
|
16
|
-
|
|
17
|
-
before do
|
|
18
|
-
skip_on_error(Mongo::Error::NoServerAvailable, 'Mongo not available') do
|
|
19
|
-
begin
|
|
20
|
-
collection.drop
|
|
21
|
-
rescue Mongo::Error::OperationFailure
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
collection.create
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it_should_behave_like 'a flipper adapter'
|
|
28
|
-
|
|
29
|
-
it 'configures itself on load' do
|
|
30
|
-
Flipper.configuration = nil
|
|
31
|
-
Flipper.instance = nil
|
|
32
|
-
|
|
33
|
-
silence { load 'flipper/adapters/mongo.rb' }
|
|
34
|
-
|
|
35
|
-
ENV["MONGO_URL"] = ENV.fetch("MONGO_URL", "mongodb://127.0.0.1:27017/testing")
|
|
36
|
-
expect(Flipper.adapter.adapter).to be_a(Flipper::Adapters::Mongo)
|
|
37
|
-
end
|
|
38
|
-
end
|
data/test/adapters/mongo_test.rb
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
require 'flipper/adapters/mongo'
|
|
3
|
-
|
|
4
|
-
class MongoTest < MiniTest::Test
|
|
5
|
-
prepend Flipper::Test::SharedAdapterTests
|
|
6
|
-
|
|
7
|
-
def setup
|
|
8
|
-
host = ENV.fetch('MONGODB_HOST', '127.0.0.1')
|
|
9
|
-
port = '27017'
|
|
10
|
-
logger = Logger.new('/dev/null')
|
|
11
|
-
client = Mongo::Client.new(["#{host}:#{port}"],
|
|
12
|
-
server_selection_timeout: 0.01,
|
|
13
|
-
database: 'testing',
|
|
14
|
-
logger: logger)
|
|
15
|
-
collection = client['testing']
|
|
16
|
-
begin
|
|
17
|
-
collection.drop
|
|
18
|
-
collection.create
|
|
19
|
-
rescue Mongo::Error::NoServerAvailable
|
|
20
|
-
ENV['CI'] ? raise : skip('Mongo not available')
|
|
21
|
-
rescue Mongo::Error::OperationFailure
|
|
22
|
-
end
|
|
23
|
-
@adapter = Flipper::Adapters::Mongo.new(collection)
|
|
24
|
-
end
|
|
25
|
-
end
|