versionaire 12.0.1 → 12.1.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: 769818a4d08698f98c8ffca2b83d5703e0cc6570410e74f73c70443e7a31a90c
4
- data.tar.gz: 1fdc7934a9a66ea188183935016e0c1268d5bea83834e5fb3b470c73043c44db
3
+ metadata.gz: 5491ae46c08cb7f8a99682ddb9f59e0860cd7a2eb563caf027f5610bab7fc641
4
+ data.tar.gz: 46073e43dd7326186280e5c26ced3d432947678c5e9f58dcaebc90fbe9ab59ab
5
5
  SHA512:
6
- metadata.gz: da502bdb67648c51083cf7f07fa4affdf38277a567aa8ec85828c705b2e5c74d507e53769fab9c925027d71de2648d4f872c5275e058aab2357ffbf90d61d270
7
- data.tar.gz: 0bababadf95c679b81582d27a67f16524330caf5187b885cd1982d935ca540e2abc863c0d0effe5200b64a6902a25e607d9ceb1ba7096978998ab52a73c3974b
6
+ metadata.gz: d49bfe2ed44bc125d4ad0521bdffb1e960a0f60201a5408cb1bda60c708f3db37d8a91e64c6447a255d28618882b703c374dc231c41fa76b729dc74a267dd816
7
+ data.tar.gz: 79809e27fcc439583a0723f0954ec262baa2d17857b71a3ff0c8b686bb3aa911014177b44caf07f2c92ac0ae6fe7c0d9c04f50ba5d890304c27e486b1f276803
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1 @@
1
- _h��]���3��[�+�����!�V<���2��OA�^E0R�\�J��׉�<��F��?�),�2��3����U 0��o���+\ET�?olB�����.�0��E��c]8�oWmk����g`�dw��y�qN7eg|8ِ���}�Ð�k۟�>_^i��6 x��!�<Rtu��ɖ��Sq4L܍e�e^��� ��$��S�.�7w���#*�^��QS���ښ�h��kLՒ6N.P���G�R� ^jt@I�����V�`�{�GkV�2��:����rѷLh
2
- n3��e�8sY��~au���f0� ���o� �o��n�b�?���B8~m���o(�m}L�:� ��'X];�C>�����J
1
+ �DX6���9EXU��>XJ�<&�u�;5�2IO��L�wRpL�-�S�i�z���j!t�Y��o �ܤ���dCm��I��A�������Ph@n�Ug'�Y/vn#�9��d��'�F����l`O񁎀G�@��#p؃��?����ρ�O��{1c���}�m(@�(*-B'��U�j���7��MX�׼�����}~1��X>n���.�jO9���$ ��0cN�0���q!�����!\�H�HHUܣ�~-�E&*Q'/|�3���y2������>����-���K-�����pR9Iv'pI��K//��q���<};�h
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.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.1
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-19 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