semver_dialects 3.0.1 → 3.0.2
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
- data/lib/semver_dialects/boundary.rb +13 -81
- data/lib/semver_dialects/semantic_version.rb +43 -102
- data/lib/semver_dialects/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d29656d2bd4bdc5bb1cd50c3cf3853e192fbb7de944b4495c816f424d710648
|
4
|
+
data.tar.gz: adbbb1f25f05a91ac195a6e8becb823b4f412a40476a26697547d06556253868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 585e0ad23e05cbd4bade3aaf925bd38b07af390de78a7a28446cb6dad50b05a99155d8744d497fcbf6377e2013bb5740fc4bb140425f52217f5bb35312af3c53
|
7
|
+
data.tar.gz: d17f636215c7c9d338819ab56ed8bbdc6f1349bfadb34c15a860d9398d2afb3a41f4c6bc521807e3e23ee36a19f9370c295c12485d9e7de5db95fef5af3b2c22
|
@@ -5,6 +5,8 @@
|
|
5
5
|
# below all versions (negative infinity), or any version.
|
6
6
|
module SemverDialects
|
7
7
|
class Boundary
|
8
|
+
include Comparable
|
9
|
+
|
8
10
|
attr_accessor :semver
|
9
11
|
|
10
12
|
def initialize(semver)
|
@@ -15,46 +17,12 @@ module SemverDialects
|
|
15
17
|
@semver.to_s
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
other.instance_of?(AboveAll) ? true : @semver < other.semver
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def >(other)
|
27
|
-
if other.instance_of?(BelowAll)
|
28
|
-
true
|
29
|
-
else
|
30
|
-
other.instance_of?(AboveAll) ? false : @semver > other.semver
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def <=(other)
|
35
|
-
self < other || self == other
|
36
|
-
end
|
37
|
-
|
38
|
-
def >=(other)
|
39
|
-
self > other || self == other
|
40
|
-
end
|
20
|
+
def <=>(other)
|
21
|
+
return nil unless other.is_a?(Boundary)
|
22
|
+
return -1 if other.instance_of?(AboveAll)
|
23
|
+
return 1 if other.instance_of?(BelowAll)
|
41
24
|
|
42
|
-
|
43
|
-
# self cannot be BelowAll or AboveAll
|
44
|
-
if other.instance_of?(BelowAll) || other.instance_of?(AboveAll)
|
45
|
-
false
|
46
|
-
else
|
47
|
-
@semver == other.semver
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def !=(other)
|
52
|
-
# self cannot be BelowAll or AboveAll
|
53
|
-
if other.instance_of?(BelowAll) || other.instance_of?(AboveAll)
|
54
|
-
false
|
55
|
-
else
|
56
|
-
@semver != other.semver
|
57
|
-
end
|
25
|
+
semver <=> other.semver
|
58
26
|
end
|
59
27
|
|
60
28
|
def is_initial_version?
|
@@ -76,28 +44,10 @@ module SemverDialects
|
|
76
44
|
false
|
77
45
|
end
|
78
46
|
|
79
|
-
def
|
80
|
-
other.instance_of?(BelowAll)
|
81
|
-
end
|
82
|
-
|
83
|
-
def >(_other)
|
84
|
-
false
|
85
|
-
end
|
86
|
-
|
87
|
-
def <=(other)
|
88
|
-
self < other || self == other
|
89
|
-
end
|
90
|
-
|
91
|
-
def >=(other)
|
92
|
-
self > other || self == other
|
93
|
-
end
|
94
|
-
|
95
|
-
def ==(other)
|
96
|
-
(other.instance_of? BelowAll) ? true : false
|
97
|
-
end
|
47
|
+
def <=>(other)
|
48
|
+
return 0 if other.instance_of?(BelowAll)
|
98
49
|
|
99
|
-
|
100
|
-
!(self == other)
|
50
|
+
-1 if other.is_a?(Boundary)
|
101
51
|
end
|
102
52
|
end
|
103
53
|
|
@@ -115,28 +65,10 @@ module SemverDialects
|
|
115
65
|
false
|
116
66
|
end
|
117
67
|
|
118
|
-
def
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
def >(other)
|
123
|
-
other.instance_of?(AboveAll) ? false : true
|
124
|
-
end
|
125
|
-
|
126
|
-
def <=(other)
|
127
|
-
self < other || self == other
|
128
|
-
end
|
129
|
-
|
130
|
-
def >=(other)
|
131
|
-
self > other || self == other
|
132
|
-
end
|
133
|
-
|
134
|
-
def ==(other)
|
135
|
-
(other.instance_of? AboveAll) ? true : false
|
136
|
-
end
|
68
|
+
def <=>(other)
|
69
|
+
return 0 if other.instance_of?(AboveAll)
|
137
70
|
|
138
|
-
|
139
|
-
!(self == other)
|
71
|
+
1 if other.is_a?(Boundary)
|
140
72
|
end
|
141
73
|
end
|
142
74
|
end
|
@@ -2,10 +2,17 @@
|
|
2
2
|
|
3
3
|
require_relative '../utils'
|
4
4
|
|
5
|
-
# SemanticVersion represents a Semver 2 version.
|
6
|
-
# Comparison rules are the ones of Semver 2.
|
7
5
|
module SemverDialects
|
6
|
+
# SemanticVersion is a generic version class.
|
7
|
+
# It parses and compares versions of any syntax.
|
8
|
+
# It can't always be accurate because a single comparison logic
|
9
|
+
# can't possibly handle all the supported syntaxes.
|
10
|
+
# Since it's generic, it doesn't validate versions.
|
8
11
|
class SemanticVersion
|
12
|
+
include Comparable
|
13
|
+
|
14
|
+
ANY_NUMBER = 'x'
|
15
|
+
|
9
16
|
attr_reader :version_string, :prefix_segments, :suffix_segments, :segments
|
10
17
|
|
11
18
|
# String to build a regexp that matches a version.
|
@@ -89,25 +96,6 @@ module SemverDialects
|
|
89
96
|
[first_array_prefix.concat(first_array_suffix), second_array_prefix.concat(second_array_suffix)]
|
90
97
|
end
|
91
98
|
|
92
|
-
def get_equalized_prefix_arrays_for(semver_a, semver_b)
|
93
|
-
first_array_prefix = semver_a.prefix_segments.clone
|
94
|
-
second_array_prefix = semver_b.prefix_segments.clone
|
95
|
-
first_array_prefix, second_array_prefix = _get_equalized_arrays_for(first_array_prefix, second_array_prefix)
|
96
|
-
[first_array_prefix, second_array_prefix]
|
97
|
-
end
|
98
|
-
|
99
|
-
def <(other)
|
100
|
-
self_array, other_array = get_equalized_arrays_for(self, other)
|
101
|
-
(0..self_array.size - 1).each do |i|
|
102
|
-
if self_array[i] < other_array[i]
|
103
|
-
return true
|
104
|
-
elsif self_array[i] > other_array[i]
|
105
|
-
return false
|
106
|
-
end
|
107
|
-
end
|
108
|
-
false
|
109
|
-
end
|
110
|
-
|
111
99
|
def is_zero?
|
112
100
|
@prefix_segments.empty? || @prefix_segments.all?(&:is_zero?)
|
113
101
|
end
|
@@ -120,47 +108,18 @@ module SemverDialects
|
|
120
108
|
@suffix_segments.any?(&:is_post_release)
|
121
109
|
end
|
122
110
|
|
123
|
-
def
|
124
|
-
|
125
|
-
(0..self_array.size - 1).each do |i|
|
126
|
-
if self_array[i] > other_array[i]
|
127
|
-
return true
|
128
|
-
elsif self_array[i] < other_array[i]
|
129
|
-
return false
|
130
|
-
end
|
131
|
-
end
|
132
|
-
false
|
133
|
-
end
|
134
|
-
|
135
|
-
def >=(other)
|
136
|
-
self == other || self > other || self == other
|
137
|
-
end
|
138
|
-
|
139
|
-
def <=(other)
|
140
|
-
self == other || self < other
|
141
|
-
end
|
142
|
-
|
143
|
-
def ==(other)
|
144
|
-
segments_a = []
|
145
|
-
segments_b = []
|
146
|
-
|
147
|
-
segments_a += other.segments
|
148
|
-
segments_b += @segments
|
111
|
+
def <=>(other)
|
112
|
+
return nil unless other.is_a?(SemanticVersion)
|
149
113
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
end
|
114
|
+
self_array, other_array = get_equalized_arrays_for(self, other)
|
115
|
+
zipped_arrays = self_array.zip(other_array)
|
116
|
+
zipped_arrays.each do |(a, b)|
|
117
|
+
return 0 if a.wildcard? || b.wildcard?
|
155
118
|
|
156
|
-
|
157
|
-
return
|
119
|
+
cmp = a <=> b
|
120
|
+
return cmp if cmp != 0
|
158
121
|
end
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
def !=(other)
|
163
|
-
!(self == other)
|
122
|
+
0
|
164
123
|
end
|
165
124
|
|
166
125
|
def to_normalized_s
|
@@ -185,6 +144,8 @@ module SemverDialects
|
|
185
144
|
end
|
186
145
|
|
187
146
|
class SemanticVersionSegment
|
147
|
+
include Comparable
|
148
|
+
|
188
149
|
attr_accessor :normalized_group_string, :original_group_string, :is_post_release, :is_pre_release
|
189
150
|
|
190
151
|
@@group_suffixes = {
|
@@ -227,52 +188,28 @@ module SemverDialects
|
|
227
188
|
end
|
228
189
|
end
|
229
190
|
|
230
|
-
def
|
231
|
-
|
232
|
-
semver_a.to_i.send(comparator, semver_b.to_i)
|
233
|
-
elsif semver_a.number? && !semver_b.number?
|
234
|
-
if semver_b == 'X'
|
235
|
-
true
|
236
|
-
else
|
237
|
-
ret_anr_bnonr
|
238
|
-
end
|
239
|
-
elsif !semver_a.number? && semver_b.number?
|
240
|
-
if semver_a == 'X'
|
241
|
-
true
|
242
|
-
else
|
243
|
-
ret_anonr_bnr
|
244
|
-
end
|
245
|
-
elsif semver_a == 'X' || semver_b == 'X' # !semantic_version_b.group_string.is_number? && !semantic_version_agrous_string.is_number?
|
246
|
-
true
|
247
|
-
else
|
248
|
-
semver_a.send(comparator, semver_b)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
def <(other)
|
253
|
-
compare(normalized_group_string, other.normalized_group_string, true, false, :<)
|
254
|
-
end
|
255
|
-
|
256
|
-
def >(other)
|
257
|
-
compare(normalized_group_string, other.normalized_group_string, false, true, :>)
|
258
|
-
end
|
191
|
+
def <=>(other)
|
192
|
+
return nil unless other.is_a?(SemanticVersionSegment)
|
259
193
|
|
260
|
-
|
261
|
-
|
262
|
-
:>)
|
263
|
-
end
|
194
|
+
self_semver = normalized_group_string
|
195
|
+
other_semver = other.normalized_group_string
|
264
196
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
197
|
+
both_are_numbers = self_semver.number? && other_semver.number?
|
198
|
+
at_least_one_is_x = self_semver == 'X' || other_semver == 'X'
|
199
|
+
a_numeric_b_non_numeric = self_semver.number? && !other_semver.number?
|
200
|
+
b_numeric_a_non_numeric = other_semver.number? && !self_semver.number?
|
269
201
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
202
|
+
if both_are_numbers
|
203
|
+
self_semver.to_i <=> other_semver.to_i
|
204
|
+
elsif at_least_one_is_x
|
205
|
+
0
|
206
|
+
elsif a_numeric_b_non_numeric
|
207
|
+
-1
|
208
|
+
elsif b_numeric_a_non_numeric
|
209
|
+
1
|
210
|
+
else
|
211
|
+
self_semver <=> other_semver
|
212
|
+
end
|
276
213
|
end
|
277
214
|
|
278
215
|
def to_normalized_s
|
@@ -283,6 +220,10 @@ module SemverDialects
|
|
283
220
|
@version_string
|
284
221
|
end
|
285
222
|
|
223
|
+
def wildcard?
|
224
|
+
normalized_group_string == 'X'
|
225
|
+
end
|
226
|
+
|
286
227
|
def is_number?
|
287
228
|
normalized_group_string.number?
|
288
229
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semver_dialects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Thome
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-06-
|
13
|
+
date: 2024-06-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pastel
|