moneta 1.4.0 → 1.4.1

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: 667e187cf3e0d0ce7e721e07036f70e0b65f1b52818fc09eb87311872896ce95
4
- data.tar.gz: 7e9063dfa4ea6f1bfbe4bee54821c75e9a82d0f54f3f820c6e396fafeeba006a
3
+ metadata.gz: f7e5d10abbde662c609b4dad3e16871e4cb3c8571777dae41e07c9a9501d3afe
4
+ data.tar.gz: 6752b78a6a0aa701695d896e207250783d88a7835c5293f3e1a50e059b45259e
5
5
  SHA512:
6
- metadata.gz: 5e2d3880c0d3fed1ee66cb57f5ebba13a83dd7e4447ec1e99e601a85ff9bc454cf7bf4e9d62c8672324faddf9f396e4488c08400a08e1c1dd0181056655142b5
7
- data.tar.gz: 4be30ddd9249b7222c2354984815efde88ca3c8cfe65db26c13df1585bd80425cc8f55f68b869d07016183be29b4ae8495a3408fe3b67e0f27d21ef2f6de6a83
6
+ metadata.gz: 63e33a297973f0b5ee15b62d4322534d871e55ae97249865d7cce7103fee1e9cce398190ee102b72ce1179b6ac044587c544ba3c6d07a6ce0906012c717fe6fc
7
+ data.tar.gz: dd53487e54f56c8faccef18d122e1f28300fd89d5e436c338c5c6688454bf79a0025b1b05d3e3621260e0fbc134e65564239afcdc22ce487a88de61a732cedf0
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ 1.4.1
2
+
3
+ * Adapters::Mongo - deprecate :db option, document :database option (#194)
4
+ * Adapters::Mongo - add retries to increment operation
5
+
1
6
  1.4.0
2
7
 
3
8
  * Adapters::Mongo - drop support for moped gem (#182)
data/Gemfile CHANGED
@@ -99,7 +99,7 @@ end
99
99
 
100
100
  # Used for generating the feature matrix
101
101
  group :doc, optional: true do
102
- gem 'kramdown', '~> 1.17.0'
102
+ gem 'kramdown', '~> 2.3.0'
103
103
  gem 'yard', '~> 0.9.20'
104
104
  end
105
105
 
@@ -29,7 +29,7 @@ module Moneta
29
29
  # @option options [String] :user Username used to authenticate
30
30
  # @option options [String] :password Password used to authenticate
31
31
  # @option options [Integer] :port (MongoDB default port) MongoDB server port
32
- # @option options [String] :db ('moneta') MongoDB database
32
+ # @option options [String] :database ('moneta') MongoDB database
33
33
  # @option options [Integer] :expires Default expiration time
34
34
  # @option options [String] :expires_field ('expiresAt') Document field to store expiration time
35
35
  # @option options [String] :value_field ('value') Document field to store value
@@ -43,8 +43,12 @@ module Moneta
43
43
  @type_field = options.delete(:type_field) || 'type'
44
44
 
45
45
  collection = options.delete(:collection) || 'moneta'
46
- db = options.delete(:db) || 'moneta'
47
- @backend = options[:backend] ||
46
+
47
+ if options.key?(:db)
48
+ warn('Moneta::Adapters::Mongo - the :db option is deprecated and will be removed in a future version. Use :database instead')
49
+ end
50
+ database = options.delete(:database) || options.delete(:db) || 'moneta'
51
+ backend = options[:backend] ||
48
52
  begin
49
53
  host = options.delete(:host) || '127.0.0.1'
50
54
  port = options.delete(:port) || DEFAULT_PORT
@@ -53,7 +57,8 @@ module Moneta
53
57
  end
54
58
  ::Mongo::Client.new(["#{host}:#{port}"], options)
55
59
  end
56
- @backend.use(db)
60
+
61
+ @backend = backend.use(database)
57
62
  @collection = @backend[collection]
58
63
  if @backend.command(buildinfo: 1).documents.first['version'] >= '2.2'
59
64
  @collection.indexes.create_one({ @expires_field => 1 }, expire_after: 0)
@@ -111,6 +116,9 @@ module Moneta
111
116
  { :$inc => { @value_field => amount } },
112
117
  return_document: :after,
113
118
  upsert: true)[@value_field]
119
+ rescue ::Mongo::Error::OperationFailure
120
+ tries ||= 0
121
+ (tries += 1) < 3 ? retry : raise
114
122
  end
115
123
 
116
124
  # (see Proxy#create)
@@ -1,5 +1,5 @@
1
1
  module Moneta
2
2
  # Moneta version number
3
3
  # @api public
4
- VERSION = '1.4.0'.freeze
4
+ VERSION = '1.4.1'.freeze
5
5
  end
@@ -10,7 +10,6 @@ require 'rantly'
10
10
  require 'rantly/rspec_extensions'
11
11
  # rantly/shrinks
12
12
  require 'timecop'
13
- require_relative 'support/mongo_helper'
14
13
 
15
14
  class MonetaParallelFormatter < RSpec::Core::Formatters::BaseTextFormatter
16
15
  def start(*args)
@@ -366,7 +365,6 @@ RSpec.configure do |config|
366
365
 
367
366
  config.extend MonetaHelpers::ClassMethods
368
367
  config.include MonetaHelpers::InstanceMethods
369
- config.include MongoHelper, adapter: :Mongo
370
368
  end
371
369
 
372
370
  # FIXME: Get rid of this once raise_error expectations no longer generate
@@ -2,11 +2,13 @@ describe 'adapter_mongo', adapter: :Mongo do
2
2
  let(:t_res) { 0.125 }
3
3
  let(:min_ttl) { t_res }
4
4
 
5
+ let(:database) { File.basename(__FILE__, '.rb') }
6
+
5
7
  moneta_build do
6
- Moneta::Adapters::Mongo.new(mongo_config(
7
- db: File.basename(__FILE__, '.rb'),
8
+ Moneta::Adapters::Mongo.new(
9
+ database: database,
8
10
  collection: 'adapter_mongo'
9
- ))
11
+ )
10
12
  end
11
13
 
12
14
  moneta_specs ADAPTER_SPECS.with_each_key.with_native_expires.simplevalues_only
@@ -24,4 +26,16 @@ describe 'adapter_mongo', adapter: :Mongo do
24
26
  i.should be > 0 # Indicates that it took at least one sleep to expire
25
27
  query.count.should == 0
26
28
  end
29
+
30
+ it 'uses the database specified via the :database option' do
31
+ expect(store.backend.database.name).to eq database
32
+ end
33
+
34
+ it 'uses the database specified via the :db option' do
35
+ store = Moneta::Adapters::Mongo.new(
36
+ db: database,
37
+ collection: 'adapter_mongo'
38
+ )
39
+ expect(store.backend.database.name).to eq database
40
+ end
27
41
  end
@@ -3,11 +3,11 @@ describe 'adapter_mongo_with_default_expires', isolate: true, adapter: :Mongo do
3
3
  let(:min_ttl) { t_res }
4
4
 
5
5
  moneta_build do
6
- Moneta::Adapters::Mongo.new(mongo_config(
7
- db: File.basename(__FILE__, '.rb'),
6
+ Moneta::Adapters::Mongo.new(
7
+ database: File.basename(__FILE__, '.rb'),
8
8
  collection: 'adapter_mongo_with_default_expires',
9
9
  expires: min_ttl
10
- ))
10
+ )
11
11
  end
12
12
 
13
13
  moneta_specs ADAPTER_SPECS.with_each_key.with_expires.with_default_expires.simplevalues_only
@@ -2,6 +2,6 @@ describe 'standard_mongo', adapter: :Mongo do
2
2
  let(:t_res) { 0.125 }
3
3
  let(:min_ttl) { t_res }
4
4
 
5
- moneta_store :Mongo, MongoHelper::mongo_config(db: File.basename(__FILE__, '.rb'), collection: 'standard_mongo')
5
+ moneta_store :Mongo, {database: File.basename(__FILE__, '.rb'), collection: 'standard_mongo'}
6
6
  moneta_specs STANDARD_SPECS.with_native_expires.with_each_key
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moneta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Mendler
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-08-23 00:00:00.000000000 Z
14
+ date: 2020-10-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: parallel_tests
@@ -426,7 +426,6 @@ files:
426
426
  - spec/rack/moneta_store_spec.rb
427
427
  - spec/rack/session_moneta_spec.rb
428
428
  - spec/restserver.rb
429
- - spec/support/mongo_helper.rb
430
429
  - test/action_dispatch/fixtures/session_autoload_test/foo.rb
431
430
  - test/action_dispatch/session_moneta_store_test.rb
432
431
  homepage: https://github.com/moneta-rb/moneta
@@ -434,9 +433,9 @@ licenses:
434
433
  - MIT
435
434
  metadata:
436
435
  bug_tracker_uri: https://github.com/moneta-rb/moneta/issues
437
- changelog_uri: https://github.com/moneta-rb/moneta/blob/v1.4.0/CHANGES
438
- documentation_uri: https://www.rubydoc.info/gems/moneta/1.4.0
439
- source_code_uri: https://github.com/moneta-rb/moneta/tree/v1.4.0
436
+ changelog_uri: https://github.com/moneta-rb/moneta/blob/v1.4.1/CHANGES
437
+ documentation_uri: https://www.rubydoc.info/gems/moneta/1.4.1
438
+ source_code_uri: https://github.com/moneta-rb/moneta/tree/v1.4.1
440
439
  post_install_message:
441
440
  rdoc_options: []
442
441
  require_paths:
@@ -673,6 +672,5 @@ test_files:
673
672
  - spec/rack/moneta_store_spec.rb
674
673
  - spec/rack/session_moneta_spec.rb
675
674
  - spec/restserver.rb
676
- - spec/support/mongo_helper.rb
677
675
  - test/action_dispatch/fixtures/session_autoload_test/foo.rb
678
676
  - test/action_dispatch/session_moneta_store_test.rb
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MongoHelper
4
- def mongo_config(opts = {})
5
- prefix = ENV.fetch('TEST_ENV_NUMBER', '')
6
- opts.merge(collection: "#{prefix}#{opts[:collection]}")
7
- end
8
-
9
- def self.mongo_config(args)
10
- Class.include(MongoHelper).new.mongo_config(args)
11
- end
12
- end