flipper-mongo 0.20.1 → 0.21.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26f580aa0e741111f85f2af9b0231a298fae7cc563fbad0c5864e41acf2fab08
4
- data.tar.gz: 5f4219ac2b09a258a5b0bc251caf26e90d1e7bef443e03029e81826567a6d49e
3
+ metadata.gz: 791c1620bf28b30186573a6505fe599e3f94c07811f3e12975b8ec5915048dcf
4
+ data.tar.gz: 0c3e4f3b56112fd42b1a3155c1a2344ef83542c7d1c5eef85a6c4b683ff07e0f
5
5
  SHA512:
6
- metadata.gz: d45e97023ed7a46140ecc665c7fa58c7640bd1ba689db60162a184dcf2ed4b08a650917b374501051b06485389d7b26020527c36b9d85870135e67409843b083
7
- data.tar.gz: 6268e4b65fad1be5dc305c4264fc6e2d3c2bd22d2376d1694b09b13d7c8ce5ff262cf526a49c2a7cba782fae599ced2ab7d5896416821a2faacc2d144683ee04
6
+ metadata.gz: 9ea34731290fb49e34bb5069a041f13beb7f633b36c5460c6fe442c409b3062a35286c1a0c4bd25d9ea96cd008959ef7f09dcdbbc931d4ef8df70cfa49cd417b
7
+ data.tar.gz: f6e829603c37184602c4e49d0c1ce22315f3ec0d66837d80d472df5be4fde9cf4b4ea4332834fa66a27c9d20b5a3a60d4c793ebf179d7c389abe33b86e68e773
data/docs/mongo/README.md CHANGED
@@ -18,12 +18,21 @@ Or install it yourself with:
18
18
 
19
19
  ## Usage
20
20
 
21
+ In most cases, all you need to do is require the adapter. You must set the `MONGO_URL` or `FLIPPER_MONGO_URL` environment vairable to specify which Mongo database to connect to.
22
+
21
23
  ```ruby
22
- require 'flipper/adapters/mongo'
23
- collection = Mongo::Client.new(["127.0.0.1:27017"], database: 'testing')['flipper']
24
- adapter = Flipper::Adapters::Mongo.new(collection)
25
- flipper = Flipper.new(adapter)
26
- # profit...
24
+ require 'flipper-mongo`
25
+ ```
26
+
27
+ **If you need to customize the adapter**, you can add this to an initializer:
28
+
29
+ ```ruby
30
+ Flipper.configure do |config|
31
+ config.adapter do
32
+ collection = Mongo::Client.new(ENV["MONGO_URL"])["flipper"]
33
+ Flipper::Adapters::Mongo.new(collection)
34
+ end
35
+ end
27
36
  ```
28
37
 
29
38
  ## Internals
@@ -1,27 +1,20 @@
1
- require 'pathname'
1
+ require 'bundler/setup'
2
2
  require 'logger'
3
3
 
4
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
5
- lib_path = root_path.join('lib')
6
- $:.unshift(lib_path)
7
-
4
+ ENV["FLIPPER_MONGO_URL"] ||= "mongodb://127.0.0.1:#{ENV["MONGODB_PORT"] || 27017}"
8
5
  require 'flipper/adapters/mongo'
9
- Mongo::Logger.logger.level = Logger::INFO
10
- collection = Mongo::Client.new(["127.0.0.1:#{ENV["MONGODB_PORT"] || 27017}"], :database => 'testing')['flipper']
11
- adapter = Flipper::Adapters::Mongo.new(collection)
12
- flipper = Flipper.new(adapter)
13
6
 
14
- flipper[:stats].enable
7
+ Flipper[:stats].enable
15
8
 
16
- if flipper[:stats].enabled?
9
+ if Flipper[:stats].enabled?
17
10
  puts "Enabled!"
18
11
  else
19
12
  puts "Disabled!"
20
13
  end
21
14
 
22
- flipper[:stats].disable
15
+ Flipper[:stats].disable
23
16
 
24
- if flipper[:stats].enabled?
17
+ if Flipper[:stats].enabled?
25
18
  puts "Enabled!"
26
19
  else
27
20
  puts "Disabled!"
@@ -1,16 +1,9 @@
1
+ require 'bundler/setup'
1
2
  require 'pp'
2
- require 'pathname'
3
3
  require 'logger'
4
4
 
5
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
6
- lib_path = root_path.join('lib')
7
- $:.unshift(lib_path)
8
-
5
+ ENV["FLIPPER_MONGO_URL"] ||= "mongodb://127.0.0.1:#{ENV["MONGODB_PORT"] || 27017}"
9
6
  require 'flipper/adapters/mongo'
10
- Mongo::Logger.logger.level = Logger::INFO
11
- collection = Mongo::Client.new(["127.0.0.1:#{ENV["MONGODB_PORT"] || 27017}"], :database => 'testing')['flipper']
12
- adapter = Flipper::Adapters::Mongo.new(collection)
13
- flipper = Flipper.new(adapter)
14
7
 
15
8
  # Register a few groups.
16
9
  Flipper.register(:admins) { |thing| thing.admin? }
@@ -19,19 +12,19 @@ Flipper.register(:early_access) { |thing| thing.early_access? }
19
12
  # Create a user class that has flipper_id instance method.
20
13
  User = Struct.new(:flipper_id)
21
14
 
22
- flipper[:stats].enable
23
- flipper[:stats].enable_group :admins
24
- flipper[:stats].enable_group :early_access
25
- flipper[:stats].enable_actor User.new('25')
26
- flipper[:stats].enable_actor User.new('90')
27
- flipper[:stats].enable_actor User.new('180')
28
- flipper[:stats].enable_percentage_of_time 15
29
- flipper[:stats].enable_percentage_of_actors 45
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
30
23
 
31
- flipper[:search].enable
24
+ Flipper[:search].enable
32
25
 
33
26
  puts 'all docs in collection'
34
- pp collection.find.to_a
27
+ pp Flipper.adapter.adapter.collection.find.to_a
35
28
  # all docs in collection
36
29
  # [{"_id"=>"stats",
37
30
  # "actors"=>["25", "90", "180"],
@@ -44,7 +37,7 @@ pp collection.find.to_a
44
37
  puts
45
38
 
46
39
  puts 'flipper get of feature'
47
- pp adapter.get(flipper[:stats])
40
+ pp Flipper.adapter.get(Flipper[:stats])
48
41
  # flipper get of feature
49
42
  # {:boolean=>"true",
50
43
  # :groups=>#<Set: {"admins", "early_access"}>,
@@ -13,6 +13,9 @@ module Flipper
13
13
  # Public: The name of the adapter.
14
14
  attr_reader :name
15
15
 
16
+ # Public: The name of the collection storing the feature data.
17
+ attr_reader :collection
18
+
16
19
  def initialize(collection)
17
20
  @collection = collection
18
21
  @name = :mongo
@@ -173,3 +176,16 @@ module Flipper
173
176
  end
174
177
  end
175
178
  end
179
+
180
+ Flipper.configure do |config|
181
+ config.adapter do
182
+ url = ENV["FLIPPER_MONGO_URL"] || ENV["MONGO_URL"]
183
+ collection = ENV["FLIPPER_MONGO_COLLECTION"] || "flipper"
184
+
185
+ unless url
186
+ raise ArgumentError, "The MONGO_URL environment variable must be set. For example: mongodb://127.0.0.1:27017/flipper"
187
+ end
188
+
189
+ Flipper::Adapters::Mongo.new(Mongo::Client.new(url)[collection])
190
+ end
191
+ end
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.20.1'.freeze
2
+ VERSION = '0.21.0.rc2'.freeze
3
3
  end
@@ -11,17 +11,30 @@ RSpec.describe Flipper::Adapters::Mongo do
11
11
  let(:port) { ENV['MONGODB_PORT'] || 27017 }
12
12
 
13
13
  let(:client) do
14
- Mongo::Client.new(["#{host}:#{port}"], server_selection_timeout: 1, database: 'testing')
14
+ logger = Logger.new('/dev/null')
15
+ Mongo::Client.new(["#{host}:#{port}"], server_selection_timeout: 0.01, database: 'testing', logger: logger)
15
16
  end
16
17
  let(:collection) { client['testing'] }
17
18
 
18
19
  before do
19
20
  begin
20
21
  collection.drop
22
+ rescue Mongo::Error::NoServerAvailable
23
+ ENV['CI'] ? raise : skip('Mongo not available')
21
24
  rescue Mongo::Error::OperationFailure
22
25
  end
23
26
  collection.create
24
27
  end
25
28
 
26
29
  it_should_behave_like 'a flipper adapter'
30
+
31
+ it 'configures itself on load' do
32
+ Flipper.configuration = nil
33
+ Flipper.instance = nil
34
+
35
+ load 'flipper/adapters/mongo.rb'
36
+
37
+ ENV["MONGO_URL"] ||= "mongodb://127.0.0.1:27017/testing"
38
+ expect(Flipper.adapter.adapter).to be_a(Flipper::Adapters::Mongo)
39
+ end
27
40
  end
@@ -9,13 +9,15 @@ class MongoTest < MiniTest::Test
9
9
  port = '27017'
10
10
  logger = Logger.new('/dev/null')
11
11
  client = Mongo::Client.new(["#{host}:#{port}"],
12
- server_selection_timeout: 1,
12
+ server_selection_timeout: 0.01,
13
13
  database: 'testing',
14
14
  logger: logger)
15
15
  collection = client['testing']
16
16
  begin
17
17
  collection.drop
18
18
  collection.create
19
+ rescue Mongo::Error::NoServerAvailable
20
+ ENV['CI'] ? raise : skip('Mongo not available')
19
21
  rescue Mongo::Error::OperationFailure
20
22
  end
21
23
  @adapter = Flipper::Adapters::Mongo.new(collection)
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: 0.20.1
4
+ version: 0.21.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: 2020-12-31 00:00:00.000000000 Z
11
+ date: 2021-05-08 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.20.1
19
+ version: 0.21.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: 0.20.1
26
+ version: 0.21.0.rc2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mongo
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,9 +70,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - ">"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.3.1
76
76
  requirements: []
77
77
  rubygems_version: 3.0.3
78
78
  signing_key: