versionaire 12.0.0 → 12.1.0

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
  SHA256:
3
- metadata.gz: 21261c10cfcc98494c1eefc7a2bdba3a5c83c7534609e309853ae6cc1b7469c6
4
- data.tar.gz: e9f18ca039afde322d8cf33bfff1e85bf9e24c1ac9047a1660f8f4bdfde134ca
3
+ metadata.gz: 5491ae46c08cb7f8a99682ddb9f59e0860cd7a2eb563caf027f5610bab7fc641
4
+ data.tar.gz: 46073e43dd7326186280e5c26ced3d432947678c5e9f58dcaebc90fbe9ab59ab
5
5
  SHA512:
6
- metadata.gz: c60a9491ec849d8980cede474fc90873c35c69c1521549be9c2a24af9ac0a40074eef547351ae03a447455574fe98f2d209ef9e0beb917f0bb59c65d3d7a1854
7
- data.tar.gz: d59230aa45d9d0db025a6a7f85d8d8fbf51d3c876125d3c2009f400724f8c0d53b8200052ea3e17d8e480ce37e806d602329d1fd19b409af0ca7e6e0977ea1c9
6
+ metadata.gz: d49bfe2ed44bc125d4ad0521bdffb1e960a0f60201a5408cb1bda60c708f3db37d8a91e64c6447a255d28618882b703c374dc231c41fa76b729dc74a267dd816
7
+ data.tar.gz: 79809e27fcc439583a0723f0954ec262baa2d17857b71a3ff0c8b686bb3aa911014177b44caf07f2c92ac0ae6fe7c0d9c04f50ba5d890304c27e486b1f276803
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.0"
5
+ spec.version = "12.1.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/versionaire"
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.0
4
+ version: 12.1.0
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-13 00:00:00.000000000 Z
38
+ date: 2023-07-06 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: refinements
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.4.14
98
+ rubygems_version: 3.4.15
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: An immutable, thread-safe, and semantic version type.
metadata.gz.sig CHANGED
Binary file