versionaire 9.0.0 → 9.2.1

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: b5bf3f6ca78ae9c031159e94ca9c756fa50b13cdec20d434695ae8a26126d7b0
4
- data.tar.gz: b6d5c1ca4d9528e70885e9e5842d3bf32a884d3c18934c7e9d3300023fc7f583
3
+ metadata.gz: ee362c5cbe42be9177b1ec4f7f82576bf39b465d030291526051d7cba3f89766
4
+ data.tar.gz: 1c8cef6f4967e1abc9b88c5009c017cba13e51037bdb6354d2215a9d6171c746
5
5
  SHA512:
6
- metadata.gz: 8c1334716bba3802c6adb35c8be2f0066f6020314f92736d6fa935600aadf19d47c7313d6087e3bc6d7171e0dfab3472c4509fba6ff24684a4b731140ff60569
7
- data.tar.gz: 65ae92c897c984976c44c2efa6e101af3d7fda55e6ecc3ee7990b56f1d7d6d3f324ed667dde497b3715b9f0fa6764bfb74268b1d98d6d4d887b1330478196ef6
6
+ metadata.gz: 3bed3af0bd372891d25432aae32d886a56377dc82e564f55bd4dce33bb27df5cad8d226101406a235bb818329d5b0fcb4d104efebe268750b4b6771da0172073
7
+ data.tar.gz: 58b4fc773ce456a43854544617f33fe22f2c3a495d69426647130ffd6dd14303f3422e9eaa7e0f3b4c7851b3ab21111619e198c9a0a37f6c3c3ff22fdda9b712
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -257,6 +257,46 @@ version.down :patch, 3 # => "5.5.2"
257
257
  version.down :major, 6 # => Versionaire::Errors::NegativeNumber
258
258
  ----
259
259
 
260
+ === Extensions
261
+
262
+ This project supports libraries which might desire native `Version` types. Each extension _must be
263
+ explicitly required_ in order to be used since they are _optional_ by default. See below for
264
+ details.
265
+
266
+ ==== OptionParser
267
+
268
+ link:https://github.com/ruby/optparse[OptionParser] is one of Ruby's
269
+ link:https://stdgems.org[default gems] which can accept additional types not native to Ruby by
270
+ default. To extend `OptionParser` with the `Version` type, all you need to do is add these two lines
271
+ to your implementation:
272
+
273
+ . `require "versionaire/extensions/option_parser"` - This will load dependencies and register the
274
+ `Version` type with `OptionParser`.
275
+ . `instance.on "--tag VERSION", Versionaire::Version` - Specifying `Versionaire::Version` as the
276
+ second argument will ensure `OptionParser` properly casts command line input as a `Version` type.
277
+
278
+ Here's an example implementation that demonstrates full usage:
279
+
280
+ [source,ruby]
281
+ ----
282
+ require "versionaire/extensions/option_parser"
283
+
284
+ options = {}
285
+
286
+ parser = OptionParser.new do |instance|
287
+ instance.on "--tag VERSION", Versionaire::Version, "Casts to version." do |value|
288
+ options[:version] = value
289
+ end
290
+ end
291
+
292
+ parser.parse! %w[--tag 1.2.3]
293
+ puts options
294
+ ----
295
+
296
+ The above will ensure `--tag 1.2.3` is parsed as `{:version=>#<struct Versionaire::Version major=1,
297
+ minor=2, patch=3>}` within your `options` variable. Should `OptionParser` parse an invalid version,
298
+ you'll get a `OptionParser::InvalidArgument` instead.
299
+
260
300
  == Development
261
301
 
262
302
  To contribute, run:
@@ -4,9 +4,7 @@ module Versionaire
4
4
  # Refines Kernel in order to provide a top-level Version conversion function.
5
5
  module Cast
6
6
  refine Kernel do
7
- def Version object
8
- Versionaire::Version object
9
- end
7
+ def Version(object) = Versionaire::Version(object)
10
8
  end
11
9
  end
12
10
  end
@@ -4,9 +4,7 @@ module Versionaire
4
4
  module Errors
5
5
  # Thrown when not using numbers.
6
6
  class InvalidNumber < Base
7
- def initialize message = "Major, minor, and patch must be a number."
8
- super message
9
- end
7
+ def initialize(message = "Major, minor, and patch must be a number.") = super(message)
10
8
  end
11
9
  end
12
10
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+ require "versionaire"
5
+
6
+ OptionParser.accept Versionaire::Version do |value|
7
+ Versionaire::Version value
8
+ rescue Versionaire::Errors::Base
9
+ raise OptionParser::InvalidArgument, value
10
+ end
@@ -67,13 +67,9 @@ module Versionaire
67
67
  .then { |arguments| Version.with_positions(*arguments) }
68
68
  end
69
69
 
70
- def required_keys?
71
- object.keys.all? { |key| Version.members.include? key }
72
- end
70
+ def required_keys? = object.keys.all? { |key| Version.members.include? key }
73
71
 
74
- def error_message object, body
75
- "Invalid version conversion: #{object}. #{body}"
76
- end
72
+ def error_message(object, body) = "Invalid version conversion: #{object}. #{body}"
77
73
  end
78
74
 
79
75
  private_constant :Converter
@@ -5,7 +5,7 @@ module Versionaire
5
5
  module Identity
6
6
  NAME = "versionaire"
7
7
  LABEL = "Versionaire"
8
- VERSION = "9.0.0"
8
+ VERSION = "9.2.1"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
@@ -9,9 +9,7 @@ module Versionaire
9
9
 
10
10
  using Refinements::Structs
11
11
 
12
- def self.delimiter
13
- "."
14
- end
12
+ def self.delimiter = "."
15
13
 
16
14
  def self.pattern
17
15
  /
@@ -54,17 +52,11 @@ module Versionaire
54
52
  to_s <=> other.to_s
55
53
  end
56
54
 
57
- def down key, value = 1
58
- revalue(key => value) { |previous, current| previous - current }
59
- end
55
+ def down(key, value = 1) = revalue(key => value) { |previous, current| previous - current }
60
56
 
61
- def up key, value = 1
62
- revalue(key => value) { |previous, current| previous + current }
63
- end
57
+ def up(key, value = 1) = revalue(key => value) { |previous, current| previous + current }
64
58
 
65
- def to_s
66
- to_a.join self.class.delimiter
67
- end
59
+ def to_s = to_a.join(self.class.delimiter)
68
60
 
69
61
  alias_method :to_str, :to_s
70
62
  alias_method :values, :to_a
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: 9.0.0
4
+ version: 9.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  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REnDlIKK4uQ9lLxIo
26
- Y2G5xubiziKZkyfWFuSr67PIjW3Bu673D1JVBArhA1qbgQmYQcy1CkGOjo+iO8Nf
27
- 7u/QSfBHb+r/bXhKscDgPpnKwbUmvgO2+94zJG9KsrmIydlzYfsD09aXKx0t6Xy4
28
- 2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
29
- QWc=
23
+ 2CdikiiE3fJhP/gY4ggwDQYJKoZIhvcNAQELBQADggEBAEjpaOXHHp8s/7GL2qCb
24
+ YAs7urOLv9VHSPfQWAwaTMVnSsIf3Sw4xzISOP/mmfEPBPXtz61K5esrE/uTFtgb
25
+ FyjxQk2H0sEWgrRXGGNHBWQRhhEs7LP/TByoC15A0br++xLxRz4r7HBLGAWQQDpg
26
+ 66BJ2TBVjxS6K64tKbq7+ACyrOZGgTfNHACh4M076y0x0oRf/rwBrU39/KRfuhbb
27
+ cm+nNCEtO35gTmZ2bVDHLGvWazi3gJt6+huQjfXTCUUG2YYBxwhu+GPdAGQPxpf9
28
+ lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
29
+ W2A=
30
30
  -----END CERTIFICATE-----
31
- date: 2020-12-29 00:00:00.000000000 Z
31
+ date: 2021-08-07 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: refinements
@@ -61,6 +61,7 @@ files:
61
61
  - lib/versionaire/errors/cast.rb
62
62
  - lib/versionaire/errors/invalid_number.rb
63
63
  - lib/versionaire/errors/negative_number.rb
64
+ - lib/versionaire/extensions/option_parser.rb
64
65
  - lib/versionaire/function.rb
65
66
  - lib/versionaire/identity.rb
66
67
  - lib/versionaire/version.rb
@@ -87,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  requirements: []
90
- rubygems_version: 3.2.3
91
+ rubygems_version: 3.2.25
91
92
  signing_key:
92
93
  specification_version: 4
93
94
  summary: Provides an immutable, thread-safe, and semantic version type.
metadata.gz.sig CHANGED
Binary file