mongoid-compatibility 0.5.0 → 0.5.1

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: 4c9cc2a402a72a8af6bd7e28e93d8428605fe8c2
4
- data.tar.gz: 8d3c8435aa36bcdca204a5f15bc59de675c94ec4
3
+ metadata.gz: cb8def381a7ad257f0a23674cf613f8762013a52
4
+ data.tar.gz: db94cbe66a50eca96cc1d41c2e8a7f9df95b4fec
5
5
  SHA512:
6
- metadata.gz: 227f291b3660311bad79c640fa6c278822698c65ecc397462a466a511128c61c6591a881dbb014481702d1b76dfe020aeb97fa6a0d4e1503cae8ee6ee3869e82
7
- data.tar.gz: a28e3cb6ddabff170b99029529030b8dc46fee41bc11768acaca5fafcdf470d4e2af30b4ac69d2eb3ba56fdf4c4aaef4cfddfcee2dd55e5c1ea2f5ce329344c5
6
+ metadata.gz: 7b2cd8310aad4d88c0ec2ca8257adf4e943752e046a1c8ca96eaf65589b94212a261847815dbe6c38a1c319288519fc6a0717219037850339798aba5e815e136
7
+ data.tar.gz: e1898cb7f37f293c6559d7614ab4b941c04205184b9a5ce3b49889ffeeeddbcac4bfe184844110d6df046bb78e9ef25a12815dcb70e09eaa287a053b89197bae
@@ -1,17 +1,17 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2015-09-25 07:58:30 -0400 using RuboCop version 0.33.0.
3
+ # on 2017-09-13 14:18:39 -0400 using RuboCop version 0.33.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 4
9
+ # Offense count: 20
10
10
  # Configuration parameters: AllowURI, URISchemes.
11
11
  Metrics/LineLength:
12
12
  Max: 118
13
13
 
14
- # Offense count: 3
14
+ # Offense count: 4
15
15
  Style/Documentation:
16
16
  Exclude:
17
17
  - 'lib/mongoid/compatibility/object_id.rb'
@@ -1,8 +1,12 @@
1
- ### 0.5.1 (Next)
1
+ ### 0.5.2 (Next)
2
2
 
3
3
  * Your contribution here.
4
4
 
5
- ### 0.5.0
5
+ ### 0.5.1 (2017-12-02)
6
+
7
+ * [#8](https://github.com/mongoid/mongoid-compatibility/issues/8): Added `mongoidX_or_newer?` and `mongoidX_or_older?` helpers - [@dblock](https://github.com/dblock).
8
+
9
+ ### 0.5.0 (2017-09-13)
6
10
 
7
11
  * [#10](https://github.com/mongoid/mongoid-compatibility/pull/10): Compatibility with Mongoid 7.x - [@joeyAghion](https://github.com/joeyAghion).
8
12
 
data/README.md CHANGED
@@ -22,7 +22,7 @@ You may explicitly need to `require mongoid/compatibility`.
22
22
 
23
23
  #### Mongoid::Compatibility::Version
24
24
 
25
- ```
25
+ ``` ruby
26
26
  Mongoid::Compatibility::Version.mongoid2?
27
27
  # => is this Mongoid 2.x?
28
28
 
@@ -42,9 +42,19 @@ Mongoid::Compatibility::Version.mongoid7?
42
42
  # => is this Mongoid 7.x?
43
43
  ```
44
44
 
45
- #### Mongoid::Compatibility::ObjectId
45
+ Instead of checking for Mongoid 6 and 7, use `newer` and `older` helpers.
46
+
47
+ ``` ruby
48
+ Mongoid::Compatibility::Version.mongoid6_or_newer?
49
+ # => is this Mongoid 6.x or 7.x, including beta 7?
46
50
 
51
+ Mongoid::Compatibility::Version.mongoid5_or_older?
52
+ # => is this Mongoid 2.x, 3.x, 4.x or 5.x?
47
53
  ```
54
+
55
+ #### Mongoid::Compatibility::ObjectId
56
+
57
+ ``` ruby
48
58
  Mongoid::Compatibility::ObjectId.legal?('4e4d66343b39b68407000001')
49
59
  # => is this a valid BSON ID?
50
60
  ```
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Compatibility
3
- VERSION = '0.5.0'.freeze
3
+ VERSION = '0.5.1'.freeze
4
4
  end
5
5
  end
@@ -8,6 +8,14 @@ module Mongoid
8
8
  define_method "mongoid#{v}?" do
9
9
  !!Mongoid::Compatibility::Version::ClassMethods.const_get("V#{v}")
10
10
  end
11
+
12
+ define_method "mongoid#{v}_or_newer?" do
13
+ Gem::Version.new(Mongoid::VERSION).segments.first >= v
14
+ end
15
+
16
+ define_method "mongoid#{v}_or_older?" do
17
+ Gem::Version.new(Mongoid::VERSION).segments.first <= v
18
+ end
11
19
  end
12
20
  end
13
21
 
@@ -3,20 +3,52 @@ require 'spec_helper'
3
3
  describe Mongoid::Compatibility::Version do
4
4
  context 'mongoid? methods' do
5
5
  it 'only true for one version' do
6
- expect(
7
- (Mongoid::Compatibility::Version.methods - Object.methods).one? do |m|
8
- Mongoid::Compatibility::Version.send(m)
9
- end
10
- ).to be true
6
+ expect((2..7).one? do |v|
7
+ Mongoid::Compatibility::Version.send("mongoid#{v}?")
8
+ end).to be true
11
9
  end
12
- it 'defines version methods' do
13
- expect(Mongoid::Compatibility::Version.methods - Object.methods).to_not eq []
10
+ context "current version #{Mongoid::VERSION}" do
11
+ let(:version) { Mongoid::VERSION.split('.').first.to_i }
12
+ it 'mongoidX?' do
13
+ expect(Mongoid::Compatibility::Version.send("mongoid#{version}?")).to be true
14
+ end
15
+ it 'mongoidX?_or_newer?' do
16
+ expect(Mongoid::Compatibility::Version.send("mongoid#{version}_or_newer?")).to be true
17
+ if Mongoid::Compatibility::Version.respond_to?("mongoid#{version - 1}_or_newer?")
18
+ expect(Mongoid::Compatibility::Version.send("mongoid#{version - 1}_or_newer?")).to be true
19
+ end
20
+ if Mongoid::Compatibility::Version.respond_to?("mongoid#{version - 1}_or_older?")
21
+ expect(Mongoid::Compatibility::Version.send("mongoid#{version - 1}_or_older?")).to be false
22
+ end
23
+ if Mongoid::Compatibility::Version.respond_to?("mongoid#{version + 1}_or_older?")
24
+ expect(Mongoid::Compatibility::Version.send("mongoid#{version + 1}_or_older?")).to be true
25
+ end
26
+ if Mongoid::Compatibility::Version.respond_to?("mongoid#{version + 1}_or_newer?")
27
+ expect(Mongoid::Compatibility::Version.send("mongoid#{version + 1}_or_newer?")).to be false
28
+ end
29
+ end
30
+ it 'mongoidX?_or_older?' do
31
+ expect(Mongoid::Compatibility::Version.send("mongoid#{version}_or_older?")).to be true
32
+ end
14
33
  end
15
34
  (2..7).each do |v|
16
35
  context "mongoid #{v}" do
36
+ before do
37
+ stub_const('::Mongoid::VERSION', "#{v}")
38
+ stub_const("::Mongoid::Compatibility::Version::ClassMethods::V#{v}", 1)
39
+ end
17
40
  it "responds to mongoid#{v}?" do
18
41
  expect(Mongoid::Compatibility::Version).to respond_to("mongoid#{v}?")
19
42
  end
43
+ it "mongoid#{v}?" do
44
+ expect(Mongoid::Compatibility::Version.send("mongoid#{v}?")).to be true
45
+ end
46
+ it "mongoid#{v}_or_newer?" do
47
+ expect(Mongoid::Compatibility::Version.send("mongoid#{v}_or_newer?")).to be true
48
+ end
49
+ it "mongoid#{v}_or_older?" do
50
+ expect(Mongoid::Compatibility::Version.send("mongoid#{v}_or_older?")).to be true
51
+ end
20
52
  end
21
53
  end
22
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-compatibility
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-13 00:00:00.000000000 Z
11
+ date: 2017-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid