vers 1.3.1 → 2.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
- data/.ruby-version +1 -1
- data/CHANGELOG.md +29 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +27 -24
- data/lib/vers/bazel_version.rb +114 -0
- data/lib/vers/composer_version.rb +117 -0
- data/lib/vers/conan_version.rb +87 -0
- data/lib/vers/constraint.rb +7 -3
- data/lib/vers/distribution_version.rb +482 -0
- data/lib/vers/gem_version.rb +81 -0
- data/lib/vers/interval.rb +49 -33
- data/lib/vers/maven_version.rb +16 -0
- data/lib/vers/nuget_version.rb +14 -0
- data/lib/vers/parser.rb +893 -202
- data/lib/vers/pub_version.rb +59 -0
- data/lib/vers/pypi_version.rb +256 -0
- data/lib/vers/scheme.rb +52 -0
- data/lib/vers/semver_version.rb +294 -0
- data/lib/vers/special_version.rb +336 -0
- data/lib/vers/version.rb +68 -13
- data/lib/vers/version_comparison.rb +26 -0
- data/lib/vers/version_range.rb +201 -48
- data/lib/vers.rb +39 -9
- metadata +15 -4
data/lib/vers/interval.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Vers
|
|
|
11
11
|
@max = max
|
|
12
12
|
@min_inclusive = min_inclusive
|
|
13
13
|
@max_inclusive = max_inclusive
|
|
14
|
-
@scheme = scheme
|
|
14
|
+
@scheme = Scheme.canonical(scheme)
|
|
15
15
|
@empty = compute_empty
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -43,21 +43,21 @@ module Vers
|
|
|
43
43
|
min.nil? && max.nil?
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def contains?(version)
|
|
46
|
+
def contains?(version, comparison_scheme: scheme)
|
|
47
47
|
return false if empty?
|
|
48
48
|
return true if unbounded?
|
|
49
49
|
|
|
50
50
|
within_min = min.nil? ||
|
|
51
|
-
(min_inclusive ? version_compare(version, min) >= 0 : version_compare(version, min) > 0)
|
|
51
|
+
(min_inclusive ? version_compare(version, min, comparison_scheme) >= 0 : version_compare(version, min, comparison_scheme) > 0)
|
|
52
52
|
|
|
53
53
|
within_max = max.nil? ||
|
|
54
|
-
(max_inclusive ? version_compare(version, max) <= 0 : version_compare(version, max) < 0)
|
|
54
|
+
(max_inclusive ? version_compare(version, max, comparison_scheme) <= 0 : version_compare(version, max, comparison_scheme) < 0)
|
|
55
55
|
|
|
56
56
|
within_min && within_max
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def intersect(other)
|
|
60
|
-
merged_scheme =
|
|
60
|
+
merged_scheme = compatible_scheme(other)
|
|
61
61
|
return self.class.empty(scheme: merged_scheme) if empty? || other.empty?
|
|
62
62
|
|
|
63
63
|
new_min = nil
|
|
@@ -66,7 +66,7 @@ module Vers
|
|
|
66
66
|
new_max_inclusive = true
|
|
67
67
|
|
|
68
68
|
if min && other.min
|
|
69
|
-
comparison = version_compare(min, other.min)
|
|
69
|
+
comparison = version_compare(min, other.min, merged_scheme)
|
|
70
70
|
if comparison > 0
|
|
71
71
|
new_min = min
|
|
72
72
|
new_min_inclusive = min_inclusive
|
|
@@ -86,7 +86,7 @@ module Vers
|
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
if max && other.max
|
|
89
|
-
comparison = version_compare(max, other.max)
|
|
89
|
+
comparison = version_compare(max, other.max, merged_scheme)
|
|
90
90
|
if comparison < 0
|
|
91
91
|
new_max = max
|
|
92
92
|
new_max_inclusive = max_inclusive
|
|
@@ -115,19 +115,19 @@ module Vers
|
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
def union(other)
|
|
118
|
+
merged_scheme = compatible_scheme(other)
|
|
118
119
|
return other if empty?
|
|
119
120
|
return self if other.empty?
|
|
120
121
|
|
|
121
122
|
return nil unless overlaps?(other) || adjacent?(other)
|
|
122
123
|
|
|
123
|
-
merged_scheme = @scheme || other.scheme
|
|
124
124
|
new_min = nil
|
|
125
125
|
new_min_inclusive = true
|
|
126
126
|
new_max = nil
|
|
127
127
|
new_max_inclusive = true
|
|
128
128
|
|
|
129
129
|
if min && other.min
|
|
130
|
-
comparison = version_compare(min, other.min)
|
|
130
|
+
comparison = version_compare(min, other.min, merged_scheme)
|
|
131
131
|
if comparison < 0
|
|
132
132
|
new_min = min
|
|
133
133
|
new_min_inclusive = min_inclusive
|
|
@@ -138,16 +138,13 @@ module Vers
|
|
|
138
138
|
new_min = min
|
|
139
139
|
new_min_inclusive = min_inclusive || other.min_inclusive
|
|
140
140
|
end
|
|
141
|
-
elsif min.nil?
|
|
142
|
-
new_min =
|
|
143
|
-
new_min_inclusive =
|
|
144
|
-
elsif other.min.nil?
|
|
145
|
-
new_min = min
|
|
146
|
-
new_min_inclusive = min_inclusive
|
|
141
|
+
elsif min.nil? || other.min.nil?
|
|
142
|
+
new_min = nil
|
|
143
|
+
new_min_inclusive = true
|
|
147
144
|
end
|
|
148
145
|
|
|
149
146
|
if max && other.max
|
|
150
|
-
comparison = version_compare(max, other.max)
|
|
147
|
+
comparison = version_compare(max, other.max, merged_scheme)
|
|
151
148
|
if comparison > 0
|
|
152
149
|
new_max = max
|
|
153
150
|
new_max_inclusive = max_inclusive
|
|
@@ -158,12 +155,9 @@ module Vers
|
|
|
158
155
|
new_max = max
|
|
159
156
|
new_max_inclusive = max_inclusive || other.max_inclusive
|
|
160
157
|
end
|
|
161
|
-
elsif max.nil?
|
|
162
|
-
new_max =
|
|
163
|
-
new_max_inclusive =
|
|
164
|
-
elsif other.max.nil?
|
|
165
|
-
new_max = max
|
|
166
|
-
new_max_inclusive = max_inclusive
|
|
158
|
+
elsif max.nil? || other.max.nil?
|
|
159
|
+
new_max = nil
|
|
160
|
+
new_max_inclusive = true
|
|
167
161
|
end
|
|
168
162
|
|
|
169
163
|
self.class.new(
|
|
@@ -176,18 +170,19 @@ module Vers
|
|
|
176
170
|
end
|
|
177
171
|
|
|
178
172
|
def overlaps?(other)
|
|
173
|
+
merged_scheme = compatible_scheme(other)
|
|
179
174
|
return false if empty? || other.empty?
|
|
180
175
|
return true if unbounded? || other.unbounded?
|
|
181
176
|
|
|
182
177
|
# Check if the intervals can't overlap by comparing bounds directly
|
|
183
178
|
if max && other.min
|
|
184
|
-
cmp = version_compare(max, other.min)
|
|
179
|
+
cmp = version_compare(max, other.min, merged_scheme)
|
|
185
180
|
return false if cmp < 0
|
|
186
181
|
return false if cmp == 0 && (!max_inclusive || !other.min_inclusive)
|
|
187
182
|
end
|
|
188
183
|
|
|
189
184
|
if min && other.max
|
|
190
|
-
cmp = version_compare(min, other.max)
|
|
185
|
+
cmp = version_compare(min, other.max, merged_scheme)
|
|
191
186
|
return false if cmp > 0
|
|
192
187
|
return false if cmp == 0 && (!min_inclusive || !other.max_inclusive)
|
|
193
188
|
end
|
|
@@ -196,19 +191,44 @@ module Vers
|
|
|
196
191
|
end
|
|
197
192
|
|
|
198
193
|
def adjacent?(other)
|
|
194
|
+
merged_scheme = compatible_scheme(other)
|
|
199
195
|
return false if empty? || other.empty?
|
|
200
196
|
|
|
201
|
-
if max && other.min && version_compare(max, other.min) == 0
|
|
197
|
+
if max && other.min && version_compare(max, other.min, merged_scheme) == 0
|
|
202
198
|
return (max_inclusive && !other.min_inclusive) || (!max_inclusive && other.min_inclusive)
|
|
203
199
|
end
|
|
204
200
|
|
|
205
|
-
if min && other.max && version_compare(min, other.max) == 0
|
|
201
|
+
if min && other.max && version_compare(min, other.max, merged_scheme) == 0
|
|
206
202
|
return (min_inclusive && !other.max_inclusive) || (!min_inclusive && other.max_inclusive)
|
|
207
203
|
end
|
|
208
204
|
|
|
209
205
|
false
|
|
210
206
|
end
|
|
211
207
|
|
|
208
|
+
def with_scheme(value)
|
|
209
|
+
canonical = Scheme.canonical(value)
|
|
210
|
+
if scheme && canonical && scheme != canonical
|
|
211
|
+
raise ArgumentError, "Cannot combine #{scheme} and #{canonical} version ranges"
|
|
212
|
+
end
|
|
213
|
+
return self if scheme == canonical
|
|
214
|
+
|
|
215
|
+
self.class.new(
|
|
216
|
+
min: min,
|
|
217
|
+
max: max,
|
|
218
|
+
min_inclusive: min_inclusive,
|
|
219
|
+
max_inclusive: max_inclusive,
|
|
220
|
+
scheme: canonical
|
|
221
|
+
)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def compatible_scheme(other)
|
|
225
|
+
if scheme && other.scheme && scheme != other.scheme
|
|
226
|
+
raise ArgumentError, "Cannot combine #{scheme} and #{other.scheme} version ranges"
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
scheme || other.scheme
|
|
230
|
+
end
|
|
231
|
+
|
|
212
232
|
def to_s
|
|
213
233
|
return "∅" if empty?
|
|
214
234
|
return "(-∞,+∞)" if unbounded?
|
|
@@ -232,16 +252,12 @@ module Vers
|
|
|
232
252
|
end
|
|
233
253
|
end
|
|
234
254
|
|
|
235
|
-
def version_compare(a, b)
|
|
255
|
+
def version_compare(a, b, comparison_scheme = @scheme)
|
|
236
256
|
return 0 if a == b
|
|
237
257
|
return -1 if a.nil?
|
|
238
258
|
return 1 if b.nil?
|
|
239
259
|
|
|
240
|
-
|
|
241
|
-
Version.compare_with_scheme(a, b, @scheme)
|
|
242
|
-
else
|
|
243
|
-
Version.compare(a, b)
|
|
244
|
-
end
|
|
260
|
+
Version.compare_for_range(a, b, comparison_scheme)
|
|
245
261
|
end
|
|
246
262
|
end
|
|
247
|
-
end
|
|
263
|
+
end
|
data/lib/vers/maven_version.rb
CHANGED
|
@@ -214,5 +214,21 @@ module Vers
|
|
|
214
214
|
def qualifier_order(q)
|
|
215
215
|
QUALIFIER_ORDER.fetch(q, UNKNOWN_QUALIFIER_ORDER)
|
|
216
216
|
end
|
|
217
|
+
|
|
218
|
+
def valid?(value)
|
|
219
|
+
string = value.to_s.strip
|
|
220
|
+
!string.empty? && !string.match?(/[[:space:]]/)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def normalize(value)
|
|
224
|
+
value.to_s.strip
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def prerelease?(value)
|
|
228
|
+
release_order = QUALIFIER_ORDER.fetch("")
|
|
229
|
+
parse_maven_version(value.to_s.strip).any? do |component|
|
|
230
|
+
!component.is_numeric && qualifier_order(component.qualifier) < release_order
|
|
231
|
+
end
|
|
232
|
+
end
|
|
217
233
|
end
|
|
218
234
|
end
|
data/lib/vers/nuget_version.rb
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module Vers
|
|
4
4
|
module NuGetVersion
|
|
5
|
+
PATTERN = /\A[0-9]+(?:\.[0-9]+){0,3}(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?\z/
|
|
6
|
+
|
|
5
7
|
module_function
|
|
6
8
|
|
|
7
9
|
def compare(a, b)
|
|
@@ -75,5 +77,17 @@ module Vers
|
|
|
75
77
|
|
|
76
78
|
0
|
|
77
79
|
end
|
|
80
|
+
|
|
81
|
+
def valid?(value)
|
|
82
|
+
value.to_s.strip.match?(PATTERN)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def normalize(value)
|
|
86
|
+
value.to_s.strip
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def prerelease?(value)
|
|
90
|
+
!parse_nuget(value.to_s.strip)[:prerelease].empty?
|
|
91
|
+
end
|
|
78
92
|
end
|
|
79
93
|
end
|