with-version 0.1.0 → 0.2.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: a78fa4c49e7ff1cc9d33f1a9344cbe9d7ce95224693b4bf9b4e3d41ea436a40a
4
- data.tar.gz: 65d8a5357cef1b1a69aeff518f1ca1d0e35d55920166bc2ae5b6f2484982d283
3
+ metadata.gz: 8d66a01b9e2d6ababc8eecc53a40726fad9431f4e240476a5b930e7c708890b9
4
+ data.tar.gz: 3bea1d04c1a8e13297500f5c5f04cd5ffc133002b7108fd6633476e11f5e7a9d
5
5
  SHA512:
6
- metadata.gz: 6b153188b7ad108b454044f7a8717420788d61e382c8feee963361525d0933316a19793357bfbb3d5d2c99ac5f82d6f6185cb6035cda2f4a09f48dfef7543f94
7
- data.tar.gz: 1f42d854e9183a0cec864e5e48e1aa8de205646bce8ef792ceed275b13396e251e8c12c755b4c9e070cc450073892d6a33f7a200a9bf43c6357a9518fe1be66c
6
+ metadata.gz: a27a350a265ac8f94d6f2262bc4e73f7b3d40f997fcc6227165fb029bf496eac429c2464a339dc49d7432acbf5e99e6bd453e1ed43f81b3b7a1c49f9b0519cf3
7
+ data.tar.gz: 3bd7fa7bb9e06f0404a169e9ba779ade96443659d4d2e8b222617e1443a43c0c00a6ee0230e9af526e547fab2abcfdf1cc7324d739ed0765d138f2ade6d85c29
@@ -1,3 +1,7 @@
1
+ ### 0.2.0 (7/16/2020)
2
+
3
+ * Include pre-release Ruby versions in `with_minimum_ruby` - [@dblock](https://github.com/dblock).
4
+
1
5
  ### 0.1.0 (1/13/2020)
2
6
 
3
7
  * Initial public release - [@dblock](https://github.com/dblock).
@@ -1,32 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- with-version (0.1.0)
4
+ with-version (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- ast (2.4.0)
10
- diff-lcs (1.3)
9
+ ast (2.4.1)
10
+ diff-lcs (1.4.4)
11
11
  jaro_winkler (1.5.4)
12
- parallel (1.19.1)
13
- parser (2.7.0.2)
14
- ast (~> 2.4.0)
12
+ parallel (1.19.2)
13
+ parser (2.7.1.4)
14
+ ast (~> 2.4.1)
15
15
  rainbow (3.0.0)
16
16
  rake (13.0.1)
17
17
  rspec (3.9.0)
18
18
  rspec-core (~> 3.9.0)
19
19
  rspec-expectations (~> 3.9.0)
20
20
  rspec-mocks (~> 3.9.0)
21
- rspec-core (3.9.1)
22
- rspec-support (~> 3.9.1)
23
- rspec-expectations (3.9.0)
21
+ rspec-core (3.9.2)
22
+ rspec-support (~> 3.9.3)
23
+ rspec-expectations (3.9.2)
24
24
  diff-lcs (>= 1.2.0, < 2.0)
25
25
  rspec-support (~> 3.9.0)
26
26
  rspec-mocks (3.9.1)
27
27
  diff-lcs (>= 1.2.0, < 2.0)
28
28
  rspec-support (~> 3.9.0)
29
- rspec-support (3.9.2)
29
+ rspec-support (3.9.3)
30
30
  rubocop (0.79.0)
31
31
  jaro_winkler (~> 1.5.1)
32
32
  parallel (~> 1.10)
@@ -35,7 +35,7 @@ GEM
35
35
  ruby-progressbar (~> 1.7)
36
36
  unicode-display_width (>= 1.4.0, < 1.7)
37
37
  ruby-progressbar (1.10.1)
38
- unicode-display_width (1.6.0)
38
+ unicode-display_width (1.6.1)
39
39
 
40
40
  PLATFORMS
41
41
  ruby
data/README.md CHANGED
@@ -27,7 +27,7 @@ class Example
27
27
  end
28
28
  ```
29
29
 
30
- ```ruby
30
+ ```ruby
31
31
  # Ruby 2.3.0
32
32
  undefined method `dig' for #<Example:0x00007fca9388a8a0> (NoMethodError)
33
33
  ```
@@ -37,6 +37,24 @@ undefined method `dig' for # (NoMethodError)
37
37
  Digging x, y ...
38
38
  ```
39
39
 
40
+ It will automatically handle pre-release versions differently from when using `Gem::Version`, which is something developers often don't consider.
41
+
42
+ ```ruby
43
+ Gem::Version.new('2.4.0.pre') >= Gem::Version.new('2.4.0') # false
44
+ ```
45
+
46
+ ```ruby
47
+ require 'with-version'
48
+
49
+ class Example
50
+ include With::Version::Ruby
51
+
52
+ with_minimum_ruby '2.4.0' do
53
+ # also true if RUBY_VERSION = 2.4.0.pre
54
+ end
55
+ end
56
+ ```
57
+
40
58
  ## Contributing
41
59
 
42
60
  You're encouraged to contribute to this gem. See [CONTRIBUTING](CONTRIBUTING.md) for details.
@@ -11,7 +11,7 @@ module With
11
11
 
12
12
  module ClassMethods
13
13
  def with_minimum_ruby(version)
14
- if With::Version::Ruby::Version.new(RUBY_VERSION) >= With::Version::Ruby::Version.new(version)
14
+ if With::Version::Ruby::Version.new(RUBY_VERSION).release >= With::Version::Ruby::Version.new(version)
15
15
  yield
16
16
  end
17
17
  end
@@ -23,6 +23,7 @@ module With
23
23
  attr_accessor :segments
24
24
 
25
25
  def initialize(version)
26
+ @version = version
26
27
  @segments = split_to_segments(version)
27
28
  end
28
29
 
@@ -51,6 +52,20 @@ module With
51
52
  0
52
53
  end
53
54
 
55
+ def prerelease?
56
+ !!(@version =~ /[a-zA-Z]/)
57
+ end
58
+
59
+ def release
60
+ if prerelease?
61
+ segments = @segments.dup
62
+ segments.pop while segments.any? { |s| String === s }
63
+ self.class.new segments.join('.')
64
+ else
65
+ self
66
+ end
67
+ end
68
+
54
69
  private
55
70
 
56
71
  def split_to_segments(version)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module With
4
4
  module Version
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -41,4 +41,19 @@ describe With::Version::Ruby do
41
41
  expect(@versions.sort).to eq([PREV_VERSION, RUBY_VERSION])
42
42
  end
43
43
  end
44
+
45
+ RELEASE_VERSION = Gem::Version.new(RUBY_VERSION).release.to_s
46
+ PRE_RELEASE_VERSION = Gem::Version.new(RELEASE_VERSION + '.pre1').to_s
47
+
48
+ context PRE_RELEASE_VERSION do
49
+ it 'includes includes pre-release' do
50
+ extend With::Version::Ruby::ClassMethods
51
+ stub_const('RUBY_VERSION', PRE_RELEASE_VERSION)
52
+ version_included = nil
53
+ with_minimum_ruby(RELEASE_VERSION) do
54
+ version_included = RUBY_VERSION
55
+ end
56
+ expect(version_included).to eq PRE_RELEASE_VERSION
57
+ end
58
+ end
44
59
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with-version
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-13 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email: dblock@dblock.org
15
15
  executables: []
16
16
  extensions: []
@@ -36,7 +36,7 @@ homepage: http://github.com/dblock/with-version
36
36
  licenses:
37
37
  - MIT
38
38
  metadata: {}
39
- post_install_message:
39
+ post_install_message:
40
40
  rdoc_options: []
41
41
  require_paths:
42
42
  - lib
@@ -51,8 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: 1.3.6
53
53
  requirements: []
54
- rubygems_version: 3.0.6
55
- signing_key:
54
+ rubygems_version: 3.1.3
55
+ signing_key:
56
56
  specification_version: 4
57
57
  summary: Syntax sugar for version checks.
58
58
  test_files: []