flipper-mongo 0.20.3 → 0.22.0

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: 4a3bbde8df86a16bdd7e14927f80ec4c1d6ac129422a63faec1805dc7dc222d7
4
- data.tar.gz: 4fc980d1375c953520e7bec85bda5e2acd34c1dd6ce277db010926dec7c901ef
3
+ metadata.gz: 2fd4b4c082d607eeddc08d1ebdb206553ce1814fe9d9c8811d65aa0a3bfa8bfd
4
+ data.tar.gz: 5f7ac3bfbd3dfd8a397522b82a600d7a0d189d10fcb6c31b1849dcca6b6ea812
5
5
  SHA512:
6
- metadata.gz: b6679503ffdfc54c0acf541f050ef9d15aa1eba7da28a74aa7a2bd610853fcd22a91c899fecfd05ddb6c9fb20ff1ca5010c8415043f8b98b2bf1619a700cddba
7
- data.tar.gz: 87cea1102155330c4f923978f773b9616c7a2a1fb96c8ae3f5549e897b1533784a1175a8f38a8f9a7916c4b6f73af1aff9efd3b7e9ddddfa99271c6591c174d4
6
+ metadata.gz: 0f4745eade20a35ea4d016da1b3a13faf0694524255e10f1aea4d990b548c4acb1bada50d42faa44d6dc4fd3b974f9a6dd6c747f23bffb2ba4ce7cbe70c18c65
7
+ data.tar.gz: 838b7a4b7745bd9b10fcdee0c87294f236901e1f4263f369b0359260070fcc936333e1a310a5ab222062bf8ce5abb6264a5abc4d266c9eebec52476533820259
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.3'.freeze
2
+ VERSION = '0.22.0'.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.3
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-10 00:00:00.000000000 Z
11
+ date: 2021-07-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.3
19
+ version: 0.22.0
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.3
26
+ version: 0.22.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mongo
29
29
  requirement: !ruby/object:Gem::Requirement