mongoid-locker 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cffd896e4b9edf28567f50b95a4fca968a63889
4
- data.tar.gz: 705e4c702b50629be4785679f76f49166ce2b84b
3
+ metadata.gz: bf9bd7b5292b2c9ab352102fb652cc6751d4be64
4
+ data.tar.gz: 0a8eb450da8131e7808831787ae9135dae805e37
5
5
  SHA512:
6
- metadata.gz: 839d56221e31ea70ff62502cb74d74fd4b904c61ce23ffc9923c5ca05897d213a33f1e494ac30ff18ab44bc1524adc7b184bf8394c65e8761df503c7fe44b7a6
7
- data.tar.gz: a2638f06f54f87fe71b481a0d8cea49341e9ece00867a91c447efa2dcb1e577e6d6fefd2b6628a776c6b75ff4845f8e136dec2d092d40dcf6938182fff41e66a
6
+ metadata.gz: 593ddca343da2c1c107f2ef972eeaccd2c3303c1401fa5b04ed667f411ea53ca47ab6b1043e2545a6e478692f8620292f904fe606fd1f7f40c3f2c39b75b4360
7
+ data.tar.gz: fcf91faa35ebd2201a8c66debdc49e4a2cbb46c19711d14a8264a20aa778baf7ce915e5ac939d00bfeab6effc1f3df29decd7414b70599d4e6e463dc18c0b657
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --format documentation
@@ -1,15 +1,15 @@
1
1
  # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-03-12 10:43:25 -0400 using RuboCop version 0.29.1.
2
+ # on 2015-09-25 09:10:09 -0400 using RuboCop version 0.29.1.
3
3
  # The point is for the user to remove these configuration records
4
4
  # one by one as the offenses are removed from the code base.
5
5
  # Note that changes in the inspected code, or installation of new
6
6
  # versions of RuboCop, may require this file to be generated again.
7
7
 
8
- # Offense count: 1
8
+ # Offense count: 2
9
9
  Metrics/AbcSize:
10
- Max: 18
10
+ Max: 19
11
11
 
12
- # Offense count: 22
12
+ # Offense count: 25
13
13
  # Configuration parameters: AllowURI, URISchemes.
14
14
  Metrics/LineLength:
15
15
  Max: 184
@@ -19,7 +19,7 @@ Metrics/LineLength:
19
19
  Metrics/MethodLength:
20
20
  Max: 25
21
21
 
22
- # Offense count: 5
22
+ # Offense count: 6
23
23
  # Cop supports --auto-correct.
24
24
  Style/Blocks:
25
25
  Enabled: false
@@ -3,6 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.1.2
6
+ - 2.2
6
7
  - jruby-19mode
7
8
  - rbx-2
8
9
 
@@ -12,5 +13,6 @@ env:
12
13
  - MONGOID_VERSION=2
13
14
  - MONGOID_VERSION=3
14
15
  - MONGOID_VERSION=4
16
+ - MONGOID_VERSION=5
15
17
 
16
18
  cache: bundler
@@ -1,8 +1,8 @@
1
1
  # Changelog
2
2
 
3
- ## HEAD ([diff](https://github.com/afeld/mongoid-locker/compare/v0.3.2...master?w=1))
3
+ ## 0.3.3 ([diff](https://github.com/afeld/mongoid-locker/compare/v0.3.3...master?w=1))
4
4
 
5
- * your contribution here
5
+ * support Mongoid 5 - #36
6
6
 
7
7
  ## 0.3.2 ([diff](https://github.com/afeld/mongoid-locker/compare/v0.3.1...v0.3.2?w=1))
8
8
 
data/Gemfile CHANGED
@@ -1,17 +1,21 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  case ENV['MONGOID_VERSION']
4
- when /4/
4
+ when /^5/
5
+ gem 'mongoid', '~> 5.0'
6
+ when /^4/
5
7
  gem 'mongoid', '~> 4.0'
6
- when /3/
8
+ when /^3/
7
9
  gem 'mongoid', '~> 3.1'
8
- when /2/
10
+ when /^2/
9
11
  gem 'bson_ext', platforms: :ruby
10
12
  gem 'mongoid', '~> 2.8'
11
13
  else
12
- gem 'mongoid', '>= 2.8', '< 5.0'
14
+ gem 'mongoid', '>= 2.8', '< 6.0'
13
15
  end
14
16
 
17
+ gem 'mongoid-compatibility'
18
+
15
19
  group :development do
16
20
  gem 'rspec', '~> 3.0'
17
21
  gem 'bundler', '~> 1.1'
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # mongoid-locker [![Build Status](https://secure.travis-ci.org/afeld/mongoid-locker.png?branch=master)](http://travis-ci.org/afeld/mongoid-locker) [![Code Climate](https://codeclimate.com/github/afeld/mongoid-locker.png)](https://codeclimate.com/github/afeld/mongoid-locker)
1
+ # mongoid-locker [![Build Status](https://secure.travis-ci.org/afeld/mongoid-locker.svg?branch=master)](http://travis-ci.org/afeld/mongoid-locker) [![Code Climate](https://codeclimate.com/github/afeld/mongoid-locker.svg)](https://codeclimate.com/github/afeld/mongoid-locker)
2
2
 
3
3
  Document-level locking for MongoDB via Mongoid. The need arose at [Jux](https://jux.com) from multiple processes on multiple servers trying to act upon the same document and stepping on each other's toes. Mongoid-Locker is an easy way to ensure only one process can perform a certain operation on a document at a time.
4
4
 
5
- [Tested](http://travis-ci.org/afeld/mongoid-locker) against MRI 1.9.3, 2.0.0 and 2.1.2, Rubinius 2.x, and JRuby 1.9 with Mongoid 2, 3 and 4 ([where supported](http://travis-ci.org/#!/afeld/mongoid-locker)).
5
+ [Tested](http://travis-ci.org/afeld/mongoid-locker) against MRI 1.9.3, 2.0.0 and 2.1.2, Rubinius 2.x, and JRuby 1.9 with Mongoid 2, 3, 4 and 5 ([where supported](http://travis-ci.org/#!/afeld/mongoid-locker)).
6
6
 
7
7
  ## Usage
8
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -1,9 +1,9 @@
1
+ require 'mongoid/compatibility'
2
+
1
3
  module Mongoid
2
4
  module Locker
3
5
  # Normalizes queries between Mongoid 2 and 3.
4
6
  module Wrapper
5
- IS_OLD_MONGOID = Mongoid::VERSION.start_with? '2.'
6
-
7
7
  # Update the document for the provided Class matching the provided query with the provided setter.
8
8
  #
9
9
  # @param [Class] The model class
@@ -11,14 +11,13 @@ module Mongoid
11
11
  # @param [Hash] The Mongoid setter
12
12
  # @return [Boolean] true if the document was successfully updated, false otherwise
13
13
  def self.update(klass, query, setter)
14
- error_obj =
15
- if IS_OLD_MONGOID
16
- klass.collection.update(query, setter, safe: true)
17
- else
18
- klass.with(safe: true).collection.find(query).update(setter)
19
- end
20
-
21
- error_obj['n'] == 1
14
+ if Mongoid::Compatibility::Version.mongoid5?
15
+ !klass.with(safe: true).collection.find(query).find_one_and_update(setter).nil?
16
+ elsif Mongoid::Compatibility::Version.mongoid2?
17
+ klass.collection.update(query, setter, safe: true)['n'] == 1
18
+ else
19
+ klass.with(safe: true).collection.find(query).update(setter)['n'] == 1
20
+ end
22
21
  end
23
22
 
24
23
  # Determine whether the provided document is locked in the database or not.
@@ -31,7 +30,7 @@ module Mongoid
31
30
  locked_until: { '$exists' => true }
32
31
  }
33
32
 
34
- if IS_OLD_MONGOID
33
+ if Mongoid::Compatibility::Version.mongoid2?
35
34
  existing = doc.class.collection.find_one(existing_query, fields: { locked_until: 1 })
36
35
  existing ? existing['locked_until'] : nil
37
36
  else
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: mongoid-locker 0.3.2 ruby lib
5
+ # stub: mongoid-locker 0.3.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "mongoid-locker"
9
- s.version = "0.3.2"
9
+ s.version = "0.3.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Aidan Feldman"]
14
- s.date = "2015-04-29"
14
+ s.date = "2015-09-25"
15
15
  s.description = "Allows multiple processes to operate on individual documents in MongoDB while ensuring that only one can act at a time."
16
16
  s.email = "aidan.feldman@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -45,19 +45,21 @@ Gem::Specification.new do |s|
45
45
  "spec/database2.yml",
46
46
  "spec/database3.yml",
47
47
  "spec/database4.yml",
48
+ "spec/database5.yml",
48
49
  "spec/mongoid-locker_spec.rb",
49
50
  "spec/spec_helper.rb"
50
51
  ]
51
52
  s.homepage = "http://github.com/afeld/mongoid-locker"
52
53
  s.licenses = ["MIT"]
53
- s.rubygems_version = "2.4.6"
54
+ s.rubygems_version = "2.2.2"
54
55
  s.summary = "Document-level locking for MongoDB via Mongoid"
55
56
 
56
57
  if s.respond_to? :specification_version then
57
58
  s.specification_version = 4
58
59
 
59
60
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
60
- s.add_runtime_dependency(%q<mongoid>, ["< 5.0", ">= 2.8"])
61
+ s.add_runtime_dependency(%q<mongoid>, ["< 6.0", ">= 2.8"])
62
+ s.add_runtime_dependency(%q<mongoid-compatibility>, [">= 0"])
61
63
  s.add_development_dependency(%q<rspec>, ["~> 3.0"])
62
64
  s.add_development_dependency(%q<bundler>, ["~> 1.1"])
63
65
  s.add_development_dependency(%q<jeweler>, ["~> 1.8"])
@@ -66,7 +68,8 @@ Gem::Specification.new do |s|
66
68
  s.add_development_dependency(%q<rake>, [">= 0"])
67
69
  s.add_development_dependency(%q<rubocop>, ["= 0.29.1"])
68
70
  else
69
- s.add_dependency(%q<mongoid>, ["< 5.0", ">= 2.8"])
71
+ s.add_dependency(%q<mongoid>, ["< 6.0", ">= 2.8"])
72
+ s.add_dependency(%q<mongoid-compatibility>, [">= 0"])
70
73
  s.add_dependency(%q<rspec>, ["~> 3.0"])
71
74
  s.add_dependency(%q<bundler>, ["~> 1.1"])
72
75
  s.add_dependency(%q<jeweler>, ["~> 1.8"])
@@ -76,7 +79,8 @@ Gem::Specification.new do |s|
76
79
  s.add_dependency(%q<rubocop>, ["= 0.29.1"])
77
80
  end
78
81
  else
79
- s.add_dependency(%q<mongoid>, ["< 5.0", ">= 2.8"])
82
+ s.add_dependency(%q<mongoid>, ["< 6.0", ">= 2.8"])
83
+ s.add_dependency(%q<mongoid-compatibility>, [">= 0"])
80
84
  s.add_dependency(%q<rspec>, ["~> 3.0"])
81
85
  s.add_dependency(%q<bundler>, ["~> 1.1"])
82
86
  s.add_dependency(%q<jeweler>, ["~> 1.8"])
@@ -0,0 +1,7 @@
1
+ test:
2
+ # for Mongoid 5
3
+ clients:
4
+ default:
5
+ database: mongoid_locker_test
6
+ hosts:
7
+ - localhost:27017
@@ -1,7 +1,9 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
3
4
  require 'rspec'
4
5
  require 'mongoid-locker'
6
+ require 'mongoid/compatibility'
5
7
 
6
8
  ENV['RACK_ENV'] = 'test'
7
9
 
@@ -19,5 +21,11 @@ RSpec.configure do |config|
19
21
  if ENV['LOG']
20
22
  Mongoid.logger.level = Logger::DEBUG
21
23
  Moped.logger.level = Logger::DEBUG if defined? Moped
24
+ elsif Mongoid::Compatibility::Version.mongoid5?
25
+ Mongoid.logger.level = Logger::INFO
26
+ Mongo::Logger.logger.level = Logger::INFO
27
+ else
28
+ Mongoid.logger.level = Logger::INFO
29
+ Moped.logger.level = Logger::INFO if defined? Moped
22
30
  end
23
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-locker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aidan Feldman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2015-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '6.0'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2.8'
@@ -26,10 +26,24 @@ dependencies:
26
26
  requirements:
27
27
  - - "<"
28
28
  - !ruby/object:Gem::Version
29
- version: '5.0'
29
+ version: '6.0'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.8'
33
+ - !ruby/object:Gem::Dependency
34
+ name: mongoid-compatibility
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: rspec
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -163,6 +177,7 @@ files:
163
177
  - spec/database2.yml
164
178
  - spec/database3.yml
165
179
  - spec/database4.yml
180
+ - spec/database5.yml
166
181
  - spec/mongoid-locker_spec.rb
167
182
  - spec/spec_helper.rb
168
183
  homepage: http://github.com/afeld/mongoid-locker
@@ -185,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
200
  version: '0'
186
201
  requirements: []
187
202
  rubyforge_project:
188
- rubygems_version: 2.4.6
203
+ rubygems_version: 2.2.2
189
204
  signing_key:
190
205
  specification_version: 4
191
206
  summary: Document-level locking for MongoDB via Mongoid