versionaire 0.1.0 → 1.0.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +71 -72
- data/lib/versionaire/conversion.rb +49 -19
- data/lib/versionaire/errors/base.rb +2 -0
- data/lib/versionaire/errors/conversion.rb +2 -0
- data/lib/versionaire/errors/invalid_number.rb +2 -0
- data/lib/versionaire/errors/negative_number.rb +2 -0
- data/lib/versionaire/identity.rb +1 -1
- data/lib/versionaire/version.rb +11 -2
- metadata +62 -6
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34468329f30afcc69ad0decfe31ef293346aa16f
|
4
|
+
data.tar.gz: 34a6064108cc26f6d5ee3b69653962911addf75b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42567538dadd2d31ab0013bde14b6abfd58dba8617fd5c45df909c1f56fc625b1a4d6a61d4a933fc21dbae2b34bc282ba0326740f880b85839424b5f322fa193
|
7
|
+
data.tar.gz: 8f52ad15a86d56ea3df8bdddb12d6041f8eb9b697218d3b0ff6f78190870a18a1bffc12aa051589e02c4367b4928f65db10ddd8f78c416e3c6ef7b3690aab0d8
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[](https://travis-ci.org/bkuhlmann/versionaire)
|
8
8
|
[](https://www.patreon.com/bkuhlmann)
|
9
9
|
|
10
|
-
Provides immutable, semantic versioning.
|
10
|
+
Provides immutable, thread-safe, semantic versioning.
|
11
11
|
|
12
12
|
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
13
13
|
|
@@ -18,16 +18,19 @@ Provides immutable, semantic versioning.
|
|
18
18
|
- [Requirements](#requirements)
|
19
19
|
- [Setup](#setup)
|
20
20
|
- [Usage](#usage)
|
21
|
-
- [
|
22
|
-
- [Math](#math)
|
23
|
-
- [Add](#add)
|
24
|
-
- [Subtract](#subtract)
|
25
|
-
- [Comparisons](#comparisons)
|
21
|
+
- [Initialization](#initialization)
|
26
22
|
- [Equality](#equality)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
- [Value (`#==`)](#value-)
|
24
|
+
- [Hash (`#eql?`)](#hash-eql)
|
25
|
+
- [Case (`#===`)](#case-)
|
26
|
+
- [Identity (`#equal?`)](#identity-equal)
|
27
|
+
- [Conversions](#conversions)
|
28
|
+
- [Function (Casting)](#function-casting)
|
29
|
+
- [Implicit](#implicit)
|
30
|
+
- [Explicit](#explicit)
|
31
|
+
- [Math](#math)
|
32
|
+
- [Addition](#addition)
|
33
|
+
- [Subtraction](#subtraction)
|
31
34
|
- [Tests](#tests)
|
32
35
|
- [Versioning](#versioning)
|
33
36
|
- [Code of Conduct](#code-of-conduct)
|
@@ -41,14 +44,12 @@ Provides immutable, semantic versioning.
|
|
41
44
|
# Features
|
42
45
|
|
43
46
|
- Provides [Semantic Versioning](http://semver.org).
|
44
|
-
- Provides immutable version instances.
|
45
|
-
- Provides conversions (casts) from a `String`, `Array`, `Hash`, or `Version` to a
|
46
|
-
- Provides impicit conversion to a `String`.
|
47
|
-
- Provides explicit conversions to a `String`, `Array`, and a `Hash`.
|
47
|
+
- Provides immutable, thread-safe version instances.
|
48
|
+
- Provides conversions (casts) from a `String`, `Array`, `Hash`, or `Version` to a `Version`.
|
48
49
|
|
49
50
|
# Screencasts
|
50
51
|
|
51
|
-
|
52
|
+
[](https://asciinema.org/a/40455)
|
52
53
|
|
53
54
|
# Requirements
|
54
55
|
|
@@ -74,7 +75,7 @@ Add the following to your Gemfile:
|
|
74
75
|
|
75
76
|
# Usage
|
76
77
|
|
77
|
-
##
|
78
|
+
## Initialization
|
78
79
|
|
79
80
|
A new version can be initialized in a variety of ways:
|
80
81
|
|
@@ -83,80 +84,72 @@ A new version can be initialized in a variety of ways:
|
|
83
84
|
Versionaire::Version.new major: 1, minor: 2 # "1.2.0"
|
84
85
|
Versionaire::Version.new major: 1, minor: 2, maintenance: 3 # "1.2.3"
|
85
86
|
|
86
|
-
##
|
87
|
+
## Equality
|
87
88
|
|
88
|
-
|
89
|
+
### Value (`#==`)
|
89
90
|
|
90
|
-
|
91
|
+
Equality is deterimined by the state of the object. This means that a version is equal to another version as long as
|
92
|
+
all of the values (i.e. state) are equal to each other. Example:
|
91
93
|
|
92
|
-
|
93
|
-
|
94
|
-
|
94
|
+
version_a = Versionaire::Version.new major: 1
|
95
|
+
version_b = Versionaire::Version.new major: 2
|
96
|
+
version_c = Versionaire::Version.new major: 1
|
95
97
|
|
96
|
-
|
98
|
+
version_a == version_a # true
|
99
|
+
version_a == version_b # false
|
100
|
+
version_a == version_c # true
|
97
101
|
|
98
|
-
|
99
|
-
version_2 = Versionaire::Version.new major: 1, minor: 1, maintenance: 1
|
100
|
-
version_1 - version_2 # "0.1.2"
|
102
|
+
Knowning this, versions can be compared against one another too:
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
-
|
104
|
+
version_a > version_b # false
|
105
|
+
version_a < version_b # true
|
106
|
+
version_a.between? version_c, version_b # true
|
105
107
|
|
106
|
-
|
108
|
+
### Hash (`#eql?`)
|
107
109
|
|
108
|
-
|
110
|
+
Behaves exactly as `#==`.
|
109
111
|
|
110
|
-
|
111
|
-
version_2 = Versionaire::Version.new major: 5
|
112
|
+
### Case (`#===`)
|
112
113
|
|
113
|
-
|
114
|
-
version_1 == version_2 # false
|
115
|
-
version_1 < version_2 # true
|
114
|
+
Behaves exactly as `#==`.
|
116
115
|
|
117
|
-
|
116
|
+
### Identity (`#equal?`)
|
118
117
|
|
119
|
-
|
118
|
+
Works like any other standard Ruby object where an object is equal only to itself.
|
120
119
|
|
121
|
-
|
122
|
-
|
123
|
-
|
120
|
+
version_a = Versionaire::Version.new major: 1
|
121
|
+
version_b = Versionaire::Version.new major: 2
|
122
|
+
version_c = Versionaire::Version.new major: 1
|
124
123
|
|
125
|
-
|
124
|
+
version_a.equal? version_a # true
|
125
|
+
version_a.equal? version_b # false
|
126
|
+
version_a.equal? version_c # false
|
126
127
|
|
127
|
-
|
128
|
+
## Conversions
|
128
129
|
|
129
|
-
|
130
|
-
identical = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
|
131
|
-
different = Versionaire::Version.new major: 3
|
130
|
+
### Function (Casting)
|
132
131
|
|
133
|
-
|
134
|
-
version == identical # true
|
135
|
-
version == different # false
|
132
|
+
The `Versionaire::Version` function is provided for explicit casting to a version:
|
136
133
|
|
137
|
-
|
138
|
-
|
139
|
-
## Identity
|
140
|
-
|
141
|
-
Identity is composed of the values that make up the version plus the class:
|
134
|
+
version = Versionaire::Version.new major: 1
|
142
135
|
|
143
|
-
|
144
|
-
|
145
|
-
|
136
|
+
Versionaire::Version "1.0.0"
|
137
|
+
Versionaire::Version [1, 0, 0]
|
138
|
+
Versionaire::Version major: 1, minor: 0, maintenance: 0
|
139
|
+
Versionaire::Version version
|
146
140
|
|
147
|
-
|
148
|
-
|
149
|
-
different.hash # -2082793513660996236
|
141
|
+
Each of these conversions will result in a version object that represents "1.0.0". When attempting to convert an
|
142
|
+
unsupported type, a `Versionaire::Errors::Conversion` exception will be thrown.
|
150
143
|
|
151
|
-
|
144
|
+
### Implicit
|
152
145
|
|
153
146
|
Implicit conversion to a `String` is supported:
|
154
147
|
|
155
148
|
"1.0.0".match Versionaire::Version.new(major: 1) # <MatchData "1.0.0">
|
156
149
|
|
157
|
-
|
150
|
+
### Explicit
|
158
151
|
|
159
|
-
Explicit
|
152
|
+
Explicit conversion to a `String`, `Array`, or `Hash` is supported:
|
160
153
|
|
161
154
|
version = Versionaire::Version.new
|
162
155
|
|
@@ -164,19 +157,25 @@ Explicit converting to a `String`, `Array`, or `Hash` is supported:
|
|
164
157
|
version.to_a # [0, 0, 0]
|
165
158
|
version.to_h # {major: 0, minor: 0, maintenance: 0}
|
166
159
|
|
167
|
-
##
|
160
|
+
## Math
|
168
161
|
|
169
|
-
|
162
|
+
Versions can be added and subtracted from each other.
|
170
163
|
|
171
|
-
|
164
|
+
### Addition
|
172
165
|
|
173
|
-
Versionaire::Version
|
174
|
-
Versionaire::Version
|
175
|
-
|
176
|
-
Versionaire::Version version
|
166
|
+
version_1 = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
|
167
|
+
version_2 = Versionaire::Version.new major: 2, minor: 5, maintenance: 7
|
168
|
+
version_1 + version_2 # "3.7.10"
|
177
169
|
|
178
|
-
|
179
|
-
|
170
|
+
### Subtraction
|
171
|
+
|
172
|
+
version_1 = Versionaire::Version.new major: 1, minor: 2, maintenance: 3
|
173
|
+
version_2 = Versionaire::Version.new major: 1, minor: 1, maintenance: 1
|
174
|
+
version_1 - version_2 # "0.1.2"
|
175
|
+
|
176
|
+
version_1 = Versionaire::Version.new major: 1
|
177
|
+
version_2 = Versionaire::Version.new major: 5
|
178
|
+
version_1 - version_2 # Fails with a Versionaire::Errors::NegativeNumber
|
180
179
|
|
181
180
|
# Tests
|
182
181
|
|
@@ -2,27 +2,57 @@
|
|
2
2
|
|
3
3
|
# The gem namespace.
|
4
4
|
module Versionaire
|
5
|
-
# Conversion function for casting
|
5
|
+
# Conversion function (strict) for casting an object into a version.
|
6
6
|
# rubocop:disable Style/MethodName
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
when
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
fail(Errors::Conversion, Errors::Conversion.array_message) unless (0..3).cover?(value.size)
|
17
|
-
Version.new Version.arguments(*value.fill(0, value.size..2))
|
18
|
-
when Hash
|
19
|
-
valid = value.keys.all? { |key| Version.keys.include? key }
|
20
|
-
fail(Errors::Conversion, Errors::Conversion.hash_message) unless valid
|
21
|
-
Version.new value
|
22
|
-
when Version then value
|
23
|
-
else fail(Errors::Conversion, Errors::Conversion.primitive_message)
|
7
|
+
def Version object
|
8
|
+
aid = VersionAid.new object
|
9
|
+
|
10
|
+
case object
|
11
|
+
when String then aid.convert_from_string
|
12
|
+
when Array then aid.convert_from_array
|
13
|
+
when Hash then aid.convert_from_hash
|
14
|
+
when Version then object
|
15
|
+
else fail Errors::Conversion, Errors::Conversion.primitive_message
|
24
16
|
end
|
25
17
|
end
|
26
|
-
|
27
18
|
module_function :Version
|
19
|
+
|
20
|
+
# Aids with converting objects into valid versions.
|
21
|
+
class VersionAid
|
22
|
+
def initialize value
|
23
|
+
@value = value
|
24
|
+
end
|
25
|
+
|
26
|
+
def convert_from_string
|
27
|
+
fail(Errors::Conversion, Errors::Conversion.string_message) unless value =~ Version.string_format
|
28
|
+
Version.new string_to_arguments
|
29
|
+
end
|
30
|
+
|
31
|
+
def convert_from_array
|
32
|
+
fail(Errors::Conversion, Errors::Conversion.array_message) unless (0..3).cover?(value.size)
|
33
|
+
Version.new array_to_arguments
|
34
|
+
end
|
35
|
+
|
36
|
+
def convert_from_hash
|
37
|
+
fail(Errors::Conversion, Errors::Conversion.hash_message) unless required_keys?
|
38
|
+
Version.new value
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :value
|
44
|
+
|
45
|
+
def string_to_arguments
|
46
|
+
Version.arguments(*value.tr("v", "").split(".").map(&:to_i))
|
47
|
+
end
|
48
|
+
|
49
|
+
def array_to_arguments
|
50
|
+
Version.arguments(*value.fill(0, value.size..2))
|
51
|
+
end
|
52
|
+
|
53
|
+
def required_keys?
|
54
|
+
value.keys.all? { |key| Version.keys.include? key }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
private_constant :VersionAid
|
28
58
|
end
|
data/lib/versionaire/identity.rb
CHANGED
data/lib/versionaire/version.rb
CHANGED
@@ -11,8 +11,17 @@ module Versionaire
|
|
11
11
|
%i(major minor maintenance)
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.
|
15
|
-
|
14
|
+
def self.string_format
|
15
|
+
/
|
16
|
+
\A # Start of string.
|
17
|
+
v? # Optional prefix.
|
18
|
+
\d{1,} # Major version.
|
19
|
+
\. # Delimiter.
|
20
|
+
\d{1,} # Minor version.
|
21
|
+
\. # Delimiter.
|
22
|
+
\d{1,} # Maintenance version.
|
23
|
+
\z # End of string.
|
24
|
+
/x
|
16
25
|
end
|
17
26
|
|
18
27
|
def self.arguments major, minor, maintenance
|
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:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
aSif+qBc6oHD7EQWPF5cZkzkIURuwNwPBngZGxIKaMAgRhjGFXzUMAaq++r59cS9
|
31
31
|
xTfQ4k6fglKEgpnLAXiKdo2c8Ym+X4rIKFfedQ==
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-03-
|
33
|
+
date: 2016-03-26 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: bundler
|
@@ -158,6 +158,62 @@ dependencies:
|
|
158
158
|
- - ">="
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
name: bond
|
163
|
+
requirement: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
type: :development
|
169
|
+
prerelease: false
|
170
|
+
version_requirements: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: wirb
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
- !ruby/object:Gem::Dependency
|
190
|
+
name: hirb
|
191
|
+
requirement: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
type: :development
|
197
|
+
prerelease: false
|
198
|
+
version_requirements: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
- !ruby/object:Gem::Dependency
|
204
|
+
name: awesome_print
|
205
|
+
requirement: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - ">="
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
210
|
+
type: :development
|
211
|
+
prerelease: false
|
212
|
+
version_requirements: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - ">="
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
161
217
|
- !ruby/object:Gem::Dependency
|
162
218
|
name: rspec
|
163
219
|
requirement: !ruby/object:Gem::Requirement
|
@@ -256,7 +312,7 @@ dependencies:
|
|
256
312
|
- - ">="
|
257
313
|
- !ruby/object:Gem::Version
|
258
314
|
version: '0'
|
259
|
-
description: Provides immutable, semantic versioning.
|
315
|
+
description: Provides immutable, thread-safe, semantic versioning.
|
260
316
|
email:
|
261
317
|
- brooke@alchemists.io
|
262
318
|
executables: []
|
@@ -288,9 +344,9 @@ require_paths:
|
|
288
344
|
- lib
|
289
345
|
required_ruby_version: !ruby/object:Gem::Requirement
|
290
346
|
requirements:
|
291
|
-
- - "
|
347
|
+
- - "~>"
|
292
348
|
- !ruby/object:Gem::Version
|
293
|
-
version: '
|
349
|
+
version: '2.3'
|
294
350
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
295
351
|
requirements:
|
296
352
|
- - ">="
|
@@ -301,5 +357,5 @@ rubyforge_project:
|
|
301
357
|
rubygems_version: 2.6.2
|
302
358
|
signing_key:
|
303
359
|
specification_version: 4
|
304
|
-
summary: Provides immutable, semantic versioning.
|
360
|
+
summary: Provides immutable, thread-safe, semantic versioning.
|
305
361
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|