flipper-mongo 0.20.4 → 0.21.0.rc1

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: 8ce1519b9304db568f9a6b58c808910867dcc7073839e3544d1a5cab5204826d
4
- data.tar.gz: 555f2be0730ff3adca735223e7a858209b9f7a50563a438a608d4dee65633d52
3
+ metadata.gz: 3a403acdc5b237a26d9b056342aab9bc4dc769f0637f0590fc92f4048cc61b31
4
+ data.tar.gz: c52237113cbaca943efa097e0f842149a4a5d1b9d69714ed6a0ed4f61655397d
5
5
  SHA512:
6
- metadata.gz: 5d601f09046022046eb042d6e242fc0b30c69413eecc7a6067015a546ca4ac14448227e31514ad57dcaa1672f92d0fb366f332d1d74afd2477504fc3c2cf7428
7
- data.tar.gz: 29b5249977946a22127a51f4325db1709723a1bc5757b2229bbd4eac986132945e92e05da789a1e55dd5b5c4f15b6096387af10706fc596675e7575e8fea0427
6
+ metadata.gz: e489144b55ab01ee1907a4cf10e8077f9124c2692dc45db5abd51f53e809ec45dc04fc88773ff2cf16e673950aef84bb78e89af6a138a234549744680848f22f
7
+ data.tar.gz: 2d0ac58887709a23d91e83043a1599b03855b85089e5f399d8749b9dbd0b0c2fb69362b6e825c660591e67ed5b4f5bb75ab0efdb8b5f904b02e7bb99a158ad09
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.default do
32
+ collection = Mongo::Client.new(ENV["MONGO_URL"])["flipper"]
33
+ Flipper.new(Flipper::Adapters::Mongo.new(collection))
34
+ end
35
+ end
27
36
  ```
28
37
 
29
38
  ## Internals
@@ -1,10 +1,6 @@
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
-
8
4
  require 'flipper/adapters/mongo'
9
5
  Mongo::Logger.logger.level = Logger::INFO
10
6
  collection = Mongo::Client.new(["127.0.0.1:#{ENV["MONGODB_PORT"] || 27017}"], :database => 'testing')['flipper']
@@ -1,11 +1,7 @@
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
-
9
5
  require 'flipper/adapters/mongo'
10
6
  Mongo::Logger.logger.level = Logger::INFO
11
7
  collection = Mongo::Client.new(["127.0.0.1:#{ENV["MONGODB_PORT"] || 27017}"], :database => 'testing')['flipper']
data/lib/flipper-mongo.rb CHANGED
@@ -1 +1,14 @@
1
1
  require 'flipper/adapters/mongo'
2
+
3
+ Flipper.configure do |config|
4
+ config.default do
5
+ url = ENV["FLIPPER_MONGO_URL"] || ENV["MONGO_URL"]
6
+ collection = ENV["FLIPPER_MONGO_COLLECTION"] || "flipper"
7
+
8
+ unless url
9
+ raise ArgumentError, "The MONGO_URL environment variable must be set. For example: mongodb://127.0.0.1:27017/flipper"
10
+ end
11
+
12
+ Flipper.new(Flipper::Adapters::Mongo.new(Mongo::Client.new(url)[collection]))
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.20.4'.freeze
2
+ VERSION = '0.21.0.rc1'.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-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.4
4
+ version: 0.21.0.rc1
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-03-06 00:00:00.000000000 Z
11
+ date: 2021-05-01 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.4
19
+ version: 0.21.0.rc1
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.4
26
+ version: 0.21.0.rc1
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: