versionaire 8.6.0 → 8.7.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: '086f0f72812f1c6dd5ae1597a8098c53513642ba6b642009dc7d33309dc87b84'
4
- data.tar.gz: daad3d46b8ccd0528fe9def4a0b4bd83b6b99810b909076150edce0fe6e8efcd
3
+ metadata.gz: b41a84e38c6e7d73b9ecc460bb8bbecc5d763aa11a05cac1021d16d8b3e17235
4
+ data.tar.gz: 10e14aeb64f4ca5c92eb559a594627bef37d03abb05d1029d417ce32c7b71ea0
5
5
  SHA512:
6
- metadata.gz: 7958a758fc0d40c359f26a21c3f6eb9bbaf778b8dbfe82b9f798f15b5bfd5333ca1275554ea908a76a35539408578a8c9025386b14379983788e8d1ebdd47222
7
- data.tar.gz: 8646bfa7633a29cf08a75231df02eb55fc04f8d0ef8fc7b7c1e77b2361b8967f508ea2caa1444367e0d3fd683537babf14d2338773965a3a17c1d5ea272fffd2
6
+ metadata.gz: 5673376e2e87acee93d11e1ef4283d18bd89fea650c9fd77018263ad3a7a1e9f9041139f38d69c881540a4810eb0035dd307c5343a2dfc114d564d47c7825af1
7
+ data.tar.gz: 88cc980f9c39af47d3443d3348894e8189487c378a402c537e6565d53cb1f18f753892fcec26c7f41274d6bc1a4ea2b1d902708e12c6b68eed029b8f0c6caa96
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -159,7 +159,7 @@ Implicit conversion to a `+String+` is supported:
159
159
 
160
160
  [source,ruby]
161
161
  ----
162
- "1.0.0".match Versionaire::Version[major: 1] # <MatchData "1.0.0">
162
+ "1.0.0".match Versionaire::Version[major: 1] # <MatchData "1.0.0">
163
163
  ----
164
164
 
165
165
  ==== Explicit
@@ -170,9 +170,9 @@ Explicit conversion to a `String`, `Array`, or `Hash` is supported:
170
170
  ----
171
171
  version = Versionaire::Version.new
172
172
 
173
- version.to_s # "0.0.0"
174
- version.to_a # [0, 0, 0]
175
- version.to_h # {major: 0, minor: 0, patch: 0}
173
+ version.to_s # "0.0.0"
174
+ version.to_a # [0, 0, 0]
175
+ version.to_h # {major: 0, minor: 0, patch: 0}
176
176
  ----
177
177
 
178
178
  === Comparisons
@@ -185,39 +185,76 @@ work. Example:
185
185
  version_1 = Versionaire::Version "1.0.0"
186
186
  version_2 = Versionaire::Version "2.0.0"
187
187
 
188
- version_1 < version_2 # true
189
- version_1 <= version_2 # true
190
- version_1 == version_2 # false (see Equality section above for details)
191
- version_1 > version_2 # false
192
- version_1 >= version_2 # false
193
- version_1.between? version_1, version_2 # true
194
- version_1.clamp version_1, version_2 # version_1 (added in Ruby 2.4.0)
188
+ version_1 < version_2 # true
189
+ version_1 <= version_2 # true
190
+ version_1 == version_2 # false (see Equality section above for details)
191
+ version_1 > version_2 # false
192
+ version_1 >= version_2 # false
193
+ version_1.between? version_1, version_2 # true
194
+ version_1.clamp version_1, version_2 # version_1 (added in Ruby 2.4.0)
195
195
  ----
196
196
 
197
197
  === Math
198
198
 
199
- Versions can be added and subtracted from each other.
199
+ Versions can be added, subtracted, sequentially increased, or sequentially decreased from each
200
+ other.
200
201
 
201
202
  ==== Addition
202
203
 
204
+ Versions can be added together to produce a resulting version sum.
205
+
203
206
  [source,ruby]
204
207
  ----
205
208
  version_1 = Versionaire::Version[major: 1, minor: 2, patch: 3]
206
209
  version_2 = Versionaire::Version[major: 2, minor: 5, patch: 7]
207
- version_1 + version_2 # "3.7.10"
210
+ version_1 + version_2 # "3.7.10"
208
211
  ----
209
212
 
210
213
  ==== Subtraction
211
214
 
215
+ Versions can be substracted from each other as long as there isn't a negative result.
216
+
212
217
  [source,ruby]
213
218
  ----
214
219
  version_1 = Versionaire::Version[major: 1, minor: 2, patch: 3]
215
220
  version_2 = Versionaire::Version[major: 1, minor: 1, patch: 1]
216
- version_1 - version_2 # "0.1.2"
221
+ version_1 - version_2 # "0.1.2"
217
222
 
218
223
  version_1 = Versionaire::Version[major: 1]
219
224
  version_2 = Versionaire::Version[major: 5]
220
- version_1 - version_2 # Fails with a Versionaire::Errors::NegativeNumber
225
+ version_1 - version_2 # Versionaire::Errors::NegativeNumber
226
+ ----
227
+
228
+ ==== Up
229
+
230
+ Versions can be sequentially increased or given a specific version to jump to.
231
+
232
+ [source,ruby]
233
+ ----
234
+ version = Versionaire::Version[major: 1, minor: 1, patch: 1]
235
+ version.up :major # => "2.1.1"
236
+ version.up :major, 3 # => "4.1.1"
237
+ version.up :minor # => "1.2.1"
238
+ version.up :minor, 3 # => "1.4.1"
239
+ version.up :patch # => "1.1.2"
240
+ version.up :patch, 3 # => "1.1.4"
241
+ ----
242
+
243
+ ==== Down
244
+
245
+ Versions can be sequentially decreased or given a specific version to jump to as long as the result
246
+ is not negative.
247
+
248
+ [source,ruby]
249
+ ----
250
+ version = Versionaire::Version[major: 5, minor: 5, patch: 5]
251
+ version.down :major # => "4.5.5"
252
+ version.down :major, 3 # => "2.5.5"
253
+ version.down :minor # => "5.4.5"
254
+ version.down :minor, 3 # => "5.2.5"
255
+ version.down :patch # => "5.5.4"
256
+ version.down :patch, 3 # => "5.5.2"
257
+ version.down :major, 6 # => Versionaire::Errors::NegativeNumber
221
258
  ----
222
259
 
223
260
  == Development
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "refinements/arrays"
4
+ require "refinements/structs"
5
+
3
6
  # The gem namespace.
4
7
  module Versionaire
5
8
  module_function
@@ -20,23 +23,25 @@ module Versionaire
20
23
 
21
24
  # Aids with converting objects into valid versions.
22
25
  class Converter
23
- def initialize object, filler: Filler.new
26
+ using Refinements::Arrays
27
+ using Refinements::Structs
28
+
29
+ def initialize object
24
30
  @object = object
25
- @filler = filler
26
31
  end
27
32
 
28
33
  def from_string
29
34
  body = "Use: <major>.<minor>.<patch>, <major>.<minor>, <major>, or empty string."
30
35
  fail Errors::Conversion, error_message(object, body) unless Version.regex.match? object
31
36
 
32
- Version[**string_to_arguments]
37
+ string_to_version
33
38
  end
34
39
 
35
40
  def from_array
36
41
  body = "Use: [<major>, <minor>, <patch>], [<major>, <minor>], [<major>], or []."
37
42
  fail Errors::Conversion, error_message(object, body) unless (0..3).cover? object.size
38
43
 
39
- Version[**array_to_arguments]
44
+ Version.with_positions(*object.pad(0, max: 3))
40
45
  end
41
46
 
42
47
  def from_hash
@@ -55,15 +60,11 @@ module Versionaire
55
60
 
56
61
  attr_reader :object, :filler
57
62
 
58
- def string_to_arguments
63
+ def string_to_version
59
64
  object.split(DELIMITER)
60
65
  .map(&:to_i)
61
- .then { |numbers| filler.call numbers }
62
- .then { |arguments| Version.arguments(*arguments) }
63
- end
64
-
65
- def array_to_arguments
66
- Version.arguments(*filler.call(object))
66
+ .then { |numbers| numbers.pad 0, max: 3 }
67
+ .then { |arguments| Version.with_positions(*arguments) }
67
68
  end
68
69
 
69
70
  def required_keys?
@@ -5,7 +5,7 @@ module Versionaire
5
5
  module Identity
6
6
  NAME = "versionaire"
7
7
  LABEL = "Versionaire"
8
- VERSION = "8.6.0"
8
+ VERSION = "8.7.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "refinements/structs"
4
+
3
5
  module Versionaire
4
6
  DELIMITER = "."
5
7
 
@@ -7,6 +9,8 @@ module Versionaire
7
9
  Version = Struct.new :major, :minor, :patch, keyword_init: true do
8
10
  include Comparable
9
11
 
12
+ using Refinements::Structs
13
+
10
14
  def self.regex
11
15
  /
12
16
  \A( # Start of string and OR.
@@ -30,12 +34,16 @@ module Versionaire
30
34
  freeze
31
35
  end
32
36
 
37
+ def []= key, value
38
+ super(key, value).tap { validate }
39
+ end
40
+
33
41
  def + other
34
- self.class.then { |klass| klass.new(**klass.arguments(*reduce(other, :+))) }
42
+ revalue(other.to_h) { |previous, current| previous + current }
35
43
  end
36
44
 
37
45
  def - other
38
- self.class.then { |klass| klass.new(**klass.arguments(*reduce(other, :-))) }
46
+ revalue(other.to_h) { |previous, current| previous - current }
39
47
  end
40
48
 
41
49
  def == other
@@ -48,15 +56,20 @@ module Versionaire
48
56
  to_s <=> other.to_s
49
57
  end
50
58
 
59
+ def down key, value = 1
60
+ revalue(key => value) { |previous, current| previous - current }
61
+ end
62
+
63
+ def up key, value = 1
64
+ revalue(key => value) { |previous, current| previous + current }
65
+ end
66
+
51
67
  def to_s
52
68
  to_a.join DELIMITER
53
69
  end
54
70
 
55
71
  alias_method :to_str, :to_s
56
-
57
- def to_a
58
- [major, minor, patch]
59
- end
72
+ alias_method :values, :to_a
60
73
 
61
74
  private
62
75
 
@@ -64,9 +77,5 @@ module Versionaire
64
77
  fail Errors::InvalidNumber if to_a.any? { |number| !number.is_a? Integer }
65
78
  fail Errors::NegativeNumber if to_a.any?(&:negative?)
66
79
  end
67
-
68
- def reduce other, action
69
- to_a.zip(other.to_a).map { |pair| pair.reduce action }
70
- end
71
80
  end
72
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: versionaire
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.6.0
4
+ version: 8.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,8 +28,22 @@ cert_chain:
28
28
  2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
29
29
  QWc=
30
30
  -----END CERTIFICATE-----
31
- date: 2020-12-13 00:00:00.000000000 Z
32
- dependencies: []
31
+ date: 2020-12-21 00:00:00.000000000 Z
32
+ dependencies:
33
+ - !ruby/object:Gem::Dependency
34
+ name: refinements
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '7.18'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '7.18'
33
47
  description:
34
48
  email:
35
49
  - brooke@alchemists.io
@@ -74,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  requirements: []
77
- rubygems_version: 3.2.0
91
+ rubygems_version: 3.2.2
78
92
  signing_key:
79
93
  specification_version: 4
80
94
  summary: Provides an immutable, thread-safe, and semantic version type.
metadata.gz.sig CHANGED
Binary file