versionaire 12.0.1 → 12.1.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: 769818a4d08698f98c8ffca2b83d5703e0cc6570410e74f73c70443e7a31a90c
4
- data.tar.gz: 1fdc7934a9a66ea188183935016e0c1268d5bea83834e5fb3b470c73043c44db
3
+ metadata.gz: 8ccdc85c252a158771e6fff4663216c1ec12b8911f3f9f43a946979878ef697b
4
+ data.tar.gz: 73a4212cc9694cee9369b1c85d8b643b2ff9d46b8948bdf17ae667e27551c7cc
5
5
  SHA512:
6
- metadata.gz: da502bdb67648c51083cf7f07fa4affdf38277a567aa8ec85828c705b2e5c74d507e53769fab9c925027d71de2648d4f872c5275e058aab2357ffbf90d61d270
7
- data.tar.gz: 0bababadf95c679b81582d27a67f16524330caf5187b885cd1982d935ca540e2abc863c0d0effe5200b64a6902a25e607d9ceb1ba7096978998ab52a73c3974b
6
+ metadata.gz: 89eef3d69e55a54fe7fa11293b588e5044d970d6c28b26cb9d26905488f085aa9e23c3e82c8eda4f95598100373311c6e10191ecf3b832d82dfc35618629781f
7
+ data.tar.gz: 12b167c40e71526a1461882579a13dc749e9e88707d53c6ec36cd047efc8a2c2c699311162f2369c17c690e591de16dc8313abd96781d04a09765cb9a049828d
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -2,6 +2,7 @@
2
2
  :toclevels: 5
3
3
  :figure-caption!:
4
4
 
5
+ :option_parser_link: link:https://alchemists.io/articles/ruby_option_parser[OptionParser]
5
6
  :semver_link: link:https://semver.org[Semantic Versioning]
6
7
 
7
8
  = Versionaire
@@ -77,8 +78,7 @@ Versionaire::Version[major: 1, minor: 2, patch: 3] # "1.2.3"
77
78
 
78
79
  ==== Value (`+#==+`)
79
80
 
80
- Equality is deterimined by the state of the object. This means that a version is equal to another
81
- version as long as all of the values (i.e. state) are equal to each other. Example:
81
+ Equality is determined by the state of the object. This means that a version is equal to another version as long as all of the values (i.e. state) are equal to each other. Example:
82
82
 
83
83
  [source,ruby]
84
84
  ----
@@ -91,7 +91,7 @@ version_a == version_b # false
91
91
  version_a == version_c # true
92
92
  ----
93
93
 
94
- Knowning this, versions can be compared against one another too:
94
+ Knowing this, versions can be compared against one another too:
95
95
 
96
96
  [source,ruby]
97
97
  ----
@@ -140,12 +140,11 @@ Versionaire::Version version
140
140
  ----
141
141
 
142
142
  Each of these conversions will result in a version object that represents "`1.0.0`". When attempting
143
- to convert an unsupported type, a `+Versionaire::Errors::Cast+` exception will be thrown.
143
+ to convert an unsupported type, a `Versionaire::Error` exception will be thrown.
144
144
 
145
145
  ==== Refinement
146
146
 
147
- Building upon the examples shown above, there is an even more elegant solution where you can use
148
- this gem's built-in link:https://alchemists.io/articles/ruby_refinements[refinement] support:
147
+ Building upon the above examples, a more elegant solution is to use a link:https://alchemists.io/articles/ruby_refinements[refinement]:
149
148
 
150
149
  [source,ruby]
151
150
  ----
@@ -230,6 +229,29 @@ version_1.between? version_1, version_2 # true
230
229
  version_1.clamp version_1, version_2 # version_1 (added in Ruby 2.4.0)
231
230
  ----
232
231
 
232
+ === Bumping
233
+
234
+ Versions can be bumped to next logical version with respect current version. Example:
235
+
236
+ [source,ruby]
237
+ ----
238
+ version = Versionaire::Version.new # #<struct Versionaire::Version major=0, minor=0, patch=0>
239
+ version.bump :major # #<struct Versionaire::Version major=1, minor=0, patch=0>
240
+ version.bump :minor # #<struct Versionaire::Version major=0, minor=1, patch=0>
241
+ version.bump :patch # #<struct Versionaire::Version major=0, minor=0, patch=1>
242
+
243
+ Versionaire::Version[major: 1, minor: 2, patch: 3].bump :major
244
+ #<struct Versionaire::Version major=2, minor=0, patch=0>
245
+
246
+ Versionaire::Version[major: 1, minor: 2, patch: 3].bump :minor
247
+ #<struct Versionaire::Version major=1, minor=3, patch=0>
248
+
249
+ Versionaire::Version[major: 1, minor: 2, patch: 3].bump :patch
250
+ #<struct Versionaire::Version major=1, minor=2, patch=4>
251
+ ----
252
+
253
+ You'll notice, when bumping the major or minor versions, lower precision gets zeroed out in order to provide the next logical version.
254
+
233
255
  === Math
234
256
 
235
257
  Versions can be added, subtracted, sequentially increased, or sequentially decreased from each
@@ -258,7 +280,7 @@ version_1 - version_2 # "0.1.2"
258
280
 
259
281
  version_1 = Versionaire::Version[major: 1]
260
282
  version_2 = Versionaire::Version[major: 5]
261
- version_1 - version_2 # Versionaire::Errors::NegativeNumber
283
+ version_1 - version_2 # Versionaire::Error
262
284
  ----
263
285
 
264
286
  ==== Up
@@ -290,7 +312,7 @@ version.down :minor # => "5.4.5"
290
312
  version.down :minor, 3 # => "5.2.5"
291
313
  version.down :patch # => "5.5.4"
292
314
  version.down :patch, 3 # => "5.5.2"
293
- version.down :major, 6 # => Versionaire::Errors::NegativeNumber
315
+ version.down :major, 6 # => Versionaire::Error
294
316
  ----
295
317
 
296
318
  === Extensions
@@ -301,15 +323,10 @@ details.
301
323
 
302
324
  ==== OptionParser
303
325
 
304
- link:https://github.com/ruby/optparse[OptionParser] is one of Ruby's
305
- link:https://stdgems.org[default gems] which can accept additional types not native to Ruby by
306
- default. To extend `OptionParser` with the `Version` type, all you need to do is add these two lines
307
- to your implementation:
326
+ {option_parser_link} is one of Ruby's link:https://stdgems.org[default gems] which can accept additional types not native to Ruby by default. To extend `OptionParser` with the `Version` type, all you need to do is add these two lines to your implementation:
308
327
 
309
- . `require "versionaire/extensions/option_parser"` - This will load dependencies and register the
310
- `Version` type with `OptionParser`.
311
- . `instance.on "--tag VERSION", Versionaire::Version` - Specifying `Versionaire::Version` as the
312
- second argument will ensure `OptionParser` properly casts command line input as a `Version` type.
328
+ . `require "versionaire/extensions/option_parser"`: This will load dependencies and register the `Version` type with `OptionParser`.
329
+ . `act.on "--tag VERSION", Versionaire::Version`: Specifying `Versionaire::Version` as the second argument will ensure `OptionParser` properly casts command line input as a `Version` type.
313
330
 
314
331
  Here's an example implementation that demonstrates full usage:
315
332
 
@@ -319,19 +336,18 @@ require "versionaire/extensions/option_parser"
319
336
 
320
337
  options = {}
321
338
 
322
- parser = OptionParser.new do |instance|
323
- instance.on "--tag VERSION", Versionaire::Version, "Casts to version." do |value|
339
+ parser = OptionParser.new do |act|
340
+ act.on "--tag VERSION", Versionaire::Version, "Casts to version." do |value|
324
341
  options[:version] = value
325
342
  end
326
343
  end
327
344
 
328
- parser.parse! %w[--tag 1.2.3]
345
+ parser.parse %w[--tag 1.2.3]
329
346
  puts options
330
347
  ----
331
348
 
332
- The above will ensure `--tag 1.2.3` is parsed as `{:version=>#<struct Versionaire::Version major=1,
333
- minor=2, patch=3>}` within your `options` variable. Should `OptionParser` parse an invalid version,
334
- you'll get a `OptionParser::InvalidArgument` instead.
349
+ The above will ensure `--tag 1.2.3` is parsed as `{version: #<struct Versionaire::Version major = 1,
350
+ minor = 2, patch = 3>}` within your `options` variable. Should `OptionParser` parse an invalid version, you'll get a `OptionParser::InvalidArgument` instead.
335
351
 
336
352
  == Development
337
353
 
@@ -7,6 +7,7 @@ module Versionaire
7
7
  Version = Struct.new :major, :minor, :patch, keyword_init: true do
8
8
  include Comparable
9
9
 
10
+ using Refinements::Arrays
10
11
  using Refinements::Structs
11
12
 
12
13
  def initialize major: 0, minor: 0, patch: 0
@@ -19,9 +20,9 @@ module Versionaire
19
20
  super(key, value).tap { validate }
20
21
  end
21
22
 
22
- def +(other) = revalue(other.to_h) { |previous, current| previous + current }
23
+ def +(other) = (revalue(other.to_h) { |previous, current| previous + current }).freeze
23
24
 
24
- def -(other) = revalue(other.to_h) { |previous, current| previous - current }
25
+ def -(other) = (revalue(other.to_h) { |previous, current| previous - current }).freeze
25
26
 
26
27
  def ==(other) = hash == other.hash
27
28
 
@@ -29,9 +30,22 @@ module Versionaire
29
30
 
30
31
  def <=>(other) = to_s <=> other.to_s
31
32
 
32
- def down(key, value = 1) = revalue(key => value) { |previous, current| previous - current }
33
+ def down key, value = 1
34
+ (revalue(key => value) { |previous, current| previous - current }).freeze
35
+ end
36
+
37
+ def up key, value = 1
38
+ (revalue(key => value) { |previous, current| previous + current }).freeze
39
+ end
33
40
 
34
- def up(key, value = 1) = revalue(key => value) { |previous, current| previous + current }
41
+ def bump key
42
+ case key
43
+ when :major then bump_major
44
+ when :minor then bump_minor
45
+ when :patch then bump_patch
46
+ else fail Error, %(Invalid key: #{key.inspect}. Use: #{members.to_sentence "or"}.)
47
+ end
48
+ end
35
49
 
36
50
  def inspect = to_s.inspect
37
51
 
@@ -50,5 +64,11 @@ module Versionaire
50
64
 
51
65
  fail Error, "Major, minor, and patch must be a positive number." if to_a.any?(&:negative?)
52
66
  end
67
+
68
+ def bump_major = merge(major: major + 1, minor: 0, patch: 0).freeze
69
+
70
+ def bump_minor = merge(major:, minor: minor + 1, patch: 0).freeze
71
+
72
+ def bump_patch = merge(major:, minor:, patch: patch + 1).freeze
53
73
  end
54
74
  end
data/versionaire.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "versionaire"
5
- spec.version = "12.0.1"
5
+ spec.version = "12.1.1"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/versionaire"
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.signing_key = Gem.default_key_path
23
23
  spec.cert_chain = [Gem.default_cert_path]
24
24
 
25
- spec.required_ruby_version = "~> 3.2"
25
+ spec.required_ruby_version = [">= 3.2", "<= 3.3"]
26
26
  spec.add_dependency "refinements", "~> 11.0"
27
27
 
28
28
  spec.files = Dir["*.gemspec", "lib/**/*"]
data.tar.gz.sig CHANGED
Binary file
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: 12.0.1
4
+ version: 12.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,7 +35,7 @@ cert_chain:
35
35
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
36
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
37
  -----END CERTIFICATE-----
38
- date: 2023-06-19 00:00:00.000000000 Z
38
+ date: 2023-11-16 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: refinements
@@ -86,16 +86,19 @@ require_paths:
86
86
  - lib
87
87
  required_ruby_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - "~>"
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: '3.2'
92
+ - - "<="
93
+ - !ruby/object:Gem::Version
94
+ version: '3.3'
92
95
  required_rubygems_version: !ruby/object:Gem::Requirement
93
96
  requirements:
94
97
  - - ">="
95
98
  - !ruby/object:Gem::Version
96
99
  version: '0'
97
100
  requirements: []
98
- rubygems_version: 3.4.14
101
+ rubygems_version: 3.4.22
99
102
  signing_key:
100
103
  specification_version: 4
101
104
  summary: An immutable, thread-safe, and semantic version type.
metadata.gz.sig CHANGED
Binary file