nuget_versions 0.9.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 +7 -0
- data/README.md +191 -0
- data/lib/nuget_versions/nuget_version.rb +81 -0
- data/lib/nuget_versions/semantic_version.rb +122 -0
- data/lib/nuget_versions/version_comparer.rb +48 -0
- data/lib/nuget_versions.rb +3 -0
- metadata +78 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f98426e0ba617b4850dd393413fc3903512065fd50eda4b4c8f8113f521eaf61
|
|
4
|
+
data.tar.gz: 34443a387d83d688af43749bee5567daeb66a3f23101fab06661ac2fd3bf1a31
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 34ea17015d284886b274c9d89e56f13019050715dea6500dfeb4cfc414955c75abd66dd57d41913d26874de56876ddd0391ae8ee7a02a5e5a44e16c76f1afc86
|
|
7
|
+
data.tar.gz: 84146c7f6c2021c59c6b1d4e0aa91a50a66b4632533724a3caa0711f7debbb65cf695efc7259908f5097b2b99fd72bcb5203821aec02a3e9815c85a58699f44c
|
data/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# NuGetVersions
|
|
2
|
+
|
|
3
|
+
This Gem contains components for parsing & working with version numbers, as NuGet assigns them to packages. The NuGet versioning scheme is a superset of Semantic Versioning (http://semver.org). The components in this library are loosely based on the version number classes in the NuGet client source code.
|
|
4
|
+
|
|
5
|
+
## Class: `SemanticVersion`
|
|
6
|
+
|
|
7
|
+
This class is a basic implementation of Semantic Versions with no extensions. This allows version numbers of the form `x.y.z-prerelease+metadata`, where `-prerelease` and `+metadata` are each optional.
|
|
8
|
+
|
|
9
|
+
### Creating
|
|
10
|
+
|
|
11
|
+
There are three main ways to create an instance of `SemanticVersion`:
|
|
12
|
+
|
|
13
|
+
#### Constructor: `SemanticVersion.new`
|
|
14
|
+
|
|
15
|
+
The `SemanticVersion` constructor has arguments for all 5 parts of the version. The prerelease ("release label") and metadata parts are optional, and default to `nil`.
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
version = SemanticVersion.new(1, 2, 3) # "1.2.3"
|
|
19
|
+
version = SemanticVersion.new(1, 2, 3, "alpha") # "1.2.3-alpha"
|
|
20
|
+
version = SemanticVersion.new(1, 2, 3, "alpha.4") # "1.2.3-alpha.4"
|
|
21
|
+
version = SemanticVersion.new(1, 2, 3, ["alpha", "4"]) # "1.2.3-alpha.4"
|
|
22
|
+
version = SemanticVersion.new(1, 2, 3, "alpha", "bugfix") # "1.2.3-alpha+bugfix"
|
|
23
|
+
version = SemanticVersion.new(1, 2, 3, nil, "bugfix") # "1.2.3+bugfix"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
#### Copy: `SemanticVersion.copy_of`
|
|
27
|
+
|
|
28
|
+
If you have an existing instance of `SemanticVersion`, you can make another instance with equivalent values by calling the `copy_of` method on the class.
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
version = ...
|
|
32
|
+
|
|
33
|
+
version2 = SemanticVersion.copy_of(version)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
This can be used to convert a `NuGetVersion` (below) to a `SemanticVersion`, as a `NuGetVersion` is a `kind_of? SemanticVersion`.
|
|
37
|
+
|
|
38
|
+
#### Parse: `SemanticVersion.parse`, `SemanticVersion.try_parse`
|
|
39
|
+
|
|
40
|
+
If you have a version number in string form, you can convert it to a `SemanticVersion` object using one of the parse methods on the class. The method `SemanticVersion.parse` raises an exception if the string is not in a valid format, while `SemanticVersion.try_parse` returns `nil`.
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
version = SemanticVersion.parse("1.2.3") # "1.2.3"
|
|
44
|
+
version = SemanticVersion.parse("1.2.3-alpha.4") # "1.2.3-alpha.4"
|
|
45
|
+
version = SemanticVersion.parse("1.2.3+bugfix") # "1.2.3+bugfix"
|
|
46
|
+
version = SemanticVersion.parse("1.2.3.4") # EXCEPTION
|
|
47
|
+
version = SemanticVersion.try_parse("1.2.3.4") # nil
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Using
|
|
51
|
+
|
|
52
|
+
The `SemanticVersion` class exposes its component values as read-only property accessors.
|
|
53
|
+
|
|
54
|
+
| Property Name | Description |
|
|
55
|
+
| ---------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
56
|
+
| `major` | The major part of the version number - `X.y.z`. |
|
|
57
|
+
| `minor` | The minor part of the version number - `x.Y.z`. |
|
|
58
|
+
| `patch` | The patch part of the version number - `x.y.Z`. |
|
|
59
|
+
| `release` | The release label of the version number, as in `alpha.4` for `1.2.3-alpha.4`. Can be `nil`. |
|
|
60
|
+
| `release_labels` | The release label of the version number as an array of components, as in `[ 'alpha', '4' ]` for `alpha.4`. |
|
|
61
|
+
| `metadata` | The metadata part of the version number, as in `bugfix` for `1.2.3+bugfix`. Can be `nil`. |
|
|
62
|
+
|
|
63
|
+
An instance of `SemanticVersion` can be converted to its string representation using the standard `to_s` method.
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
SemanticVersion.parse("1.2.3-alpha.4+bugfix").to_s # "1.2.3-alpha.4-bugfix"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Instances of `SemanticVersion` are comparable & orderable.
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
a = SemanticVersion.parse("1.2.3")
|
|
73
|
+
b = SemanticVersion.parse("1.2.4")
|
|
74
|
+
|
|
75
|
+
a < b # true
|
|
76
|
+
a <= b # true
|
|
77
|
+
a > b # false
|
|
78
|
+
a >= b # false
|
|
79
|
+
a < a # false
|
|
80
|
+
a <= a # false
|
|
81
|
+
a == a # true
|
|
82
|
+
a != a # false
|
|
83
|
+
a == b # false
|
|
84
|
+
a != b # true
|
|
85
|
+
a <=> b # -1
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Instances of `SemanticVersion` can also be compared directly with instances of `NuGetVersion`.
|
|
89
|
+
|
|
90
|
+
## Class: `NuGetVersion`
|
|
91
|
+
|
|
92
|
+
This class extends `SemanticVersion` to support NuGet's "legacy" 4-part version number scheme. This is essentially the same scheme as Semantic Version, except with four version components instead of three. Thus, version numbers such as `1.2.3.4`, `1.2.3.4-alpha` and `1.2.3.4+bugfix` are permissible, in addition to any version `SemanticVersion` accepts. Note that if the 4th component is `0`, then it is omitted.
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
NuGetVersion.parse("1.2.3.0").to_s # "1.2.3"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Creating
|
|
99
|
+
|
|
100
|
+
As with `SemanticVersion`, there are three main ways to create an instance of `NuGetVersion`:
|
|
101
|
+
|
|
102
|
+
#### Constructor: `NuGetVersion.new`
|
|
103
|
+
|
|
104
|
+
The `NuGetVersion` constructor has arguments for all 6 parts of the version. The prerelease ("release label") and metadata parts are optional, and default to `nil`. The fourth version component is also optional, and defaults to `0`.
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
version = NuGetVersion.new(1, 2, 3) # "1.2.3"
|
|
108
|
+
version = NuGetVersion.new(1, 2, 3, 0) # "1.2.3"
|
|
109
|
+
version = NuGetVersion.new(1, 2, 3, 4) # "1.2.3.4"
|
|
110
|
+
version = NuGetVersion.new(1, 2, 3, 0, "alpha") # "1.2.3-alpha"
|
|
111
|
+
version = NuGetVersion.new(1, 2, 3, 4, "alpha") # "1.2.3.4-alpha"
|
|
112
|
+
version = NuGetVersion.new(1, 2, 3, 4, "alpha.5") # "1.2.3.4-alpha.5"
|
|
113
|
+
version = NuGetVersion.new(1, 2, 3, 4, ["alpha", "5"]) # "1.2.3.4-alpha.5"
|
|
114
|
+
version = NuGetVersion.new(1, 2, 3, 4, "alpha", "bugfix") # "1.2.3.4-alpha+bugfix"
|
|
115
|
+
version = NuGetVersion.new(1, 2, 3, 4, nil, "bugfix") # "1.2.3.4+bugfix"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Copy: `NuGetVersion.copy_of`
|
|
119
|
+
|
|
120
|
+
If you have an existing instance of `NuGetVersion`, you can make another instance with equivalent values by calling the `copy_of` method on the class.
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
version = ...
|
|
124
|
+
|
|
125
|
+
version2 = NuGetVersion.copy_of(version)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
This can be used to convert a `SemanticVersion` (above) to a `NuGetVersion`. In this case, the `revision` component of the `NuGetVersion` will be `0`.
|
|
129
|
+
|
|
130
|
+
#### Parse: `NuGetVersion.parse`, `NuGetVersion.try_parse`
|
|
131
|
+
|
|
132
|
+
If you have a version number in string form, you can convert it to a `NuGetVersion` object using one of the parse methods on the class. The method `NuGetVersion.parse` raises an exception if the string is not in a valid format, while `NuGetVersion.try_parse` returns `nil`.
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
version = NuGetVersion.parse("1.2.3") # "1.2.3"
|
|
136
|
+
version = NuGetVersion.parse("1.2.3-alpha.4") # "1.2.3-alpha.4"
|
|
137
|
+
version = NuGetVersion.parse("1.2.3+bugfix") # "1.2.3+bugfix"
|
|
138
|
+
version = NuGetVersion.parse("1.2.3.4") # "1.2.3.4"
|
|
139
|
+
version = NuGetVersion.try_parse("1.2.3.4") # "1.2.3.4"
|
|
140
|
+
version = NuGetVersion.parse("1.2.3.4.5") # EXCEPTION
|
|
141
|
+
version = NuGetVersion.try_parse("1.2.3.4.5") # nil
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Using
|
|
145
|
+
|
|
146
|
+
The `NuGetVersion` class exposes its component values as read-only property accessors.
|
|
147
|
+
|
|
148
|
+
| Property Name | Description |
|
|
149
|
+
| ---------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
150
|
+
| `major` | The major part of the version number - `W.x.y.z`. |
|
|
151
|
+
| `minor` | The minor part of the version number - `w.X.y.z`. |
|
|
152
|
+
| `patch` | The patch part of the version number - `w.x.Y.z`. |
|
|
153
|
+
| `revision` | The revision part of the version number - `w.x.y.Z`. |
|
|
154
|
+
| `release` | The release label of the version number, as in `alpha.5` for `1.2.3.4-alpha.5`. Can be `nil`. |
|
|
155
|
+
| `release_labels` | The release label of the version number as an array of components, as in `[ 'alpha', '5' ]` for `alpha.5`. |
|
|
156
|
+
| `metadata` | The metadata part of the version number, as in `bugfix` for `1.2.3.4+bugfix`. Can be `nil`. |
|
|
157
|
+
|
|
158
|
+
An instance of `NuGetVersion` can be converted to its string representation using the standard `to_s` method.
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
NuGetVersion.parse("1.2.3-alpha.5+bugfix").to_s # "1.2.3-alpha.5-bugfix"
|
|
162
|
+
NuGetVersion.parse("1.2.3.0-alpha.5+bugfix").to_s # "1.2.3-alpha.5-bugfix"
|
|
163
|
+
NuGetVersion.parse("1.2.3.4-alpha.5+bugfix").to_s # "1.2.3.4-alpha.5-bugfix"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Instances of `NuGetVersion` are comparable & orderable.
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
a = NuGetVersion.parse("1.2.3.4")
|
|
170
|
+
b = NuGetVersion.parse("1.2.3.5")
|
|
171
|
+
|
|
172
|
+
a < b # true
|
|
173
|
+
a <= b # true
|
|
174
|
+
a > b # false
|
|
175
|
+
a >= b # false
|
|
176
|
+
a < a # false
|
|
177
|
+
a <= a # false
|
|
178
|
+
a == a # true
|
|
179
|
+
a != a # false
|
|
180
|
+
a == b # false
|
|
181
|
+
a != b # true
|
|
182
|
+
a <=> b # -1
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Instances of `NuGetVersion` can also be compared directly with instances of `SemanticVersion`.
|
|
186
|
+
|
|
187
|
+
## Class: `VersionComparer`
|
|
188
|
+
|
|
189
|
+
This class exists to provide the underlying implementation for the comparison operators on `SemanticVersion` and `NuGetVersion`. All of these operators are driven by a single method `VersionComparer.compare`, which returns the same type of value as the rocket ship operator `<=>`. Logically, its first argument is "subtracted" from its second argument, and if the result is negative, then `compare` returns -1. If the result is positive, `compare` returns +1. If the result is zero (i.e., the arguments have identical values), then `compare` returns 0.
|
|
190
|
+
|
|
191
|
+
This method can be called directly, and is documented as part of the interface, but in most cases it should be possible to compare instances of `SemanticVersion` and `NuGetVersion` directly, and this usage is preferred.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module NuGetVersions
|
|
2
|
+
class NuGetVersion < SemanticVersion
|
|
3
|
+
# Creates a NuGetVersion from an existing NuGetVersion
|
|
4
|
+
# Parameters:
|
|
5
|
+
# - version: Version to clone.
|
|
6
|
+
def self.copy_of(version)
|
|
7
|
+
revision = 0
|
|
8
|
+
revision = version.revision if version.respond_to? :revision
|
|
9
|
+
|
|
10
|
+
return NuGetVersion.new(version.major, version.minor, version.patch, revision, version.release_labels, version.metadata)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Creates a NuGetVersion X.Y.Z, X.Y.Z-alpha, X.Y.Z-alpha+metadata, W.X.Y.Z, W.X.Y.Z-alpha, W.X.Y.Z-alpha+metadata.
|
|
14
|
+
# Parameters:
|
|
15
|
+
# - major: W.x.y.z
|
|
16
|
+
# - minor: w.X.y.z
|
|
17
|
+
# - patch: w.x.Y.z
|
|
18
|
+
# - revision: w.x.y.Z
|
|
19
|
+
# - release_labels: Prerelease label
|
|
20
|
+
# - metadata: Build metadata
|
|
21
|
+
def initialize(major, minor, patch, revision = 0, release_labels = nil, metadata = nil)
|
|
22
|
+
super(major, minor, patch, release_labels, metadata)
|
|
23
|
+
|
|
24
|
+
@revision = revision
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
attr_reader :revision
|
|
28
|
+
|
|
29
|
+
attr_accessor :original_version
|
|
30
|
+
|
|
31
|
+
def to_s
|
|
32
|
+
return @original_version if !@original_version.nil? && !@original_version.empty?
|
|
33
|
+
|
|
34
|
+
version = "#{@major}.#{@minor}.#{@patch}"
|
|
35
|
+
version += ".#{@revision}" if revision != 0
|
|
36
|
+
version += "-#{release}" if is_prerelease?
|
|
37
|
+
version += "+#{metadata}" if has_metadata?
|
|
38
|
+
|
|
39
|
+
version
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.parse(value)
|
|
43
|
+
ver = self.try_parse(value)
|
|
44
|
+
raise "Invalid NuGet version value" if ver.nil?
|
|
45
|
+
|
|
46
|
+
ver
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.try_parse(value)
|
|
50
|
+
return nil if value.nil?
|
|
51
|
+
|
|
52
|
+
value = original_value = value.to_s if !value.is_a? String
|
|
53
|
+
|
|
54
|
+
value = value.split("+", 2)
|
|
55
|
+
|
|
56
|
+
metadata = (value.length == 2) ? value.last : nil
|
|
57
|
+
|
|
58
|
+
value = value.first.split("-", 2)
|
|
59
|
+
|
|
60
|
+
release_labels = (value.length == 2) ? value.last : nil
|
|
61
|
+
|
|
62
|
+
parts = value.first.split(".")
|
|
63
|
+
|
|
64
|
+
return nil if value.length > 4
|
|
65
|
+
|
|
66
|
+
begin
|
|
67
|
+
major = Integer(parts[0])
|
|
68
|
+
minor = (parts.length >= 2) ? Integer(parts[1]) : 0
|
|
69
|
+
patch = (parts.length >= 3) ? Integer(parts[2]) : 0
|
|
70
|
+
revision = (parts.length >= 4) ? Integer(parts[3]) : 0
|
|
71
|
+
rescue
|
|
72
|
+
return nil
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
ver = NuGetVersion.new(major, minor, patch, revision, release_labels, metadata)
|
|
76
|
+
ver.original_version = original_value
|
|
77
|
+
|
|
78
|
+
ver
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
module NuGetVersions
|
|
2
|
+
# A strict SemVer implementation
|
|
3
|
+
# Based on: NuGet.Client/NuGet.Core/NuGet.Versioning/SemanticVersion.cs from the NuGet source code.
|
|
4
|
+
class SemanticVersion
|
|
5
|
+
# Creates a SemanticVersion from an existing SemanticVersion
|
|
6
|
+
# Parameters:
|
|
7
|
+
# - version: Version to clone.
|
|
8
|
+
def self.copy_of(version)
|
|
9
|
+
return SemanticVersion.new(version.major, version.minor, version.patch, version.release_labels, version.metadata)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Creates a SemanticVersion X.Y.Z, X.Y.Z-alpha, X.Y.Z-alpha+metadata.
|
|
13
|
+
# Parameters:
|
|
14
|
+
# - major: X.y.z
|
|
15
|
+
# - minor: x.Y.z
|
|
16
|
+
# - patch: x.y.Z
|
|
17
|
+
# - release_labels: Prerelease label
|
|
18
|
+
# - metadata: Build metadata
|
|
19
|
+
def initialize(major, minor, patch, release_labels = nil, metadata = nil)
|
|
20
|
+
@major = major
|
|
21
|
+
@minor = minor
|
|
22
|
+
@patch = patch
|
|
23
|
+
|
|
24
|
+
if !release_labels.nil?
|
|
25
|
+
release_labels = release_labels.to_s.split('.') if !release_labels.kind_of? Array
|
|
26
|
+
@release_labels = release_labels
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
@metadata = metadata
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
attr_reader :major
|
|
33
|
+
attr_reader :minor
|
|
34
|
+
attr_reader :patch
|
|
35
|
+
attr_reader :release_labels
|
|
36
|
+
attr_reader :metadata
|
|
37
|
+
|
|
38
|
+
def release
|
|
39
|
+
return "" if @release_labels.nil?
|
|
40
|
+
@release_labels.join('.')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def is_prerelease?
|
|
44
|
+
!@release_labels.nil? && !@release_labels.all?(&:empty?)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def has_metadata?
|
|
48
|
+
!@metadata.nil? && !@metadata.empty?
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def to_s
|
|
52
|
+
version = "#{@major}.#{@minor}.#{@patch}"
|
|
53
|
+
version += "-#{release}" if is_prerelease?
|
|
54
|
+
version += "+#{metadata}" if has_metadata?
|
|
55
|
+
|
|
56
|
+
version
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def ==(other)
|
|
60
|
+
VersionComparer.compare(self, other) == 0
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def !=(other)
|
|
64
|
+
!(self == other)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def <(other)
|
|
68
|
+
VersionComparer.compare(self, other) == -1
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def >(other)
|
|
72
|
+
other < self
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def <=(other)
|
|
76
|
+
!(other < self)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def >=(other)
|
|
80
|
+
!(self < other)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def <=>(other)
|
|
84
|
+
VersionComparer.compare(self, other)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def self.parse(value)
|
|
88
|
+
ver = self.try_parse(value)
|
|
89
|
+
raise "Invalid semantic version value" if ver.nil?
|
|
90
|
+
|
|
91
|
+
ver
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def self.try_parse(value)
|
|
95
|
+
return nil if value.nil?
|
|
96
|
+
|
|
97
|
+
value = value.to_s if !value.is_a? String
|
|
98
|
+
|
|
99
|
+
value = value.split("+", 2)
|
|
100
|
+
|
|
101
|
+
metadata = (value.length == 2) ? value.last : nil
|
|
102
|
+
|
|
103
|
+
value = value.first.split("-", 2)
|
|
104
|
+
|
|
105
|
+
release_labels = (value.length == 2) ? value.last : nil
|
|
106
|
+
|
|
107
|
+
parts = value.first.split(".")
|
|
108
|
+
|
|
109
|
+
return nil if value.length > 3
|
|
110
|
+
|
|
111
|
+
begin
|
|
112
|
+
major = Integer(parts[0])
|
|
113
|
+
minor = (parts.length >= 2) ? Integer(parts[1]) : 0
|
|
114
|
+
patch = (parts.length >= 3) ? Integer(parts[2]) : 0
|
|
115
|
+
rescue
|
|
116
|
+
return nil
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
return SemanticVersion.new(major, minor, patch, release_labels, metadata)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module NuGetVersions
|
|
2
|
+
class VersionComparer
|
|
3
|
+
class << self
|
|
4
|
+
def compare(a, b)
|
|
5
|
+
return 0 if a.equal? b
|
|
6
|
+
return 1 if b.nil?
|
|
7
|
+
return -1 if a.nil?
|
|
8
|
+
|
|
9
|
+
result = 0
|
|
10
|
+
return result if (result = a.major <=> b.major) != 0
|
|
11
|
+
return result if (result = a.minor <=> b.minor) != 0
|
|
12
|
+
return result if (result = a.patch <=> b.patch) != 0
|
|
13
|
+
|
|
14
|
+
if a.kind_of?(NuGetVersion) && b.kind_of?(NuGetVersion)
|
|
15
|
+
return result if (result = a.revision <=> b.revision) != 0
|
|
16
|
+
else
|
|
17
|
+
return +1 if a.kind_of?(NuGetVersion) && (a.revision > 0)
|
|
18
|
+
return -1 if b.kind_of?(NuGetVersion) && (b.revision > 0)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
a_labels = a.release_labels
|
|
22
|
+
b_labels = b.release_labels
|
|
23
|
+
|
|
24
|
+
count = [a_labels.length, b_labels.length].min
|
|
25
|
+
|
|
26
|
+
for i in 0..(count - 1)
|
|
27
|
+
return -1 if i >= a_labels.length
|
|
28
|
+
return +1 if i >= b_labels.length
|
|
29
|
+
|
|
30
|
+
a_release = a_labels[i].to_s
|
|
31
|
+
b_release = b_labels[i].to_s
|
|
32
|
+
|
|
33
|
+
a_release_int = Integer(a_labels[i]) rescue nil
|
|
34
|
+
b_release_int = Integer(b_labels[i]) rescue nil
|
|
35
|
+
|
|
36
|
+
return a_release_int <=> b_release_int if !(a_release_int.nil? || b_release_int.nil?)
|
|
37
|
+
|
|
38
|
+
return +1 if !a_release_int.nil?
|
|
39
|
+
return -1 if !b_release_int.nil?
|
|
40
|
+
|
|
41
|
+
return result if (result = a_release.casecmp(b_release)) != 0
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
return (a.metadata || "").casecmp(b.metadata || "")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: nuget_versions
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.9.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jonathan Gilbert
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-07-19 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
description: Provides facilities for parsing & working with NuGet Versions, which
|
|
42
|
+
are a superset of Semantic Versions 2.0.
|
|
43
|
+
email:
|
|
44
|
+
- JonathanG@iQmetrix.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- README.md
|
|
50
|
+
- lib/nuget_versions.rb
|
|
51
|
+
- lib/nuget_versions/nuget_version.rb
|
|
52
|
+
- lib/nuget_versions/semantic_version.rb
|
|
53
|
+
- lib/nuget_versions/version_comparer.rb
|
|
54
|
+
homepage: https://github.com/logiclrd/NuGetVersions
|
|
55
|
+
licenses:
|
|
56
|
+
- LGPL-3.0+
|
|
57
|
+
metadata: {}
|
|
58
|
+
post_install_message:
|
|
59
|
+
rdoc_options: []
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0'
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - "~>"
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '2.0'
|
|
72
|
+
requirements: []
|
|
73
|
+
rubyforge_project:
|
|
74
|
+
rubygems_version: 2.7.6
|
|
75
|
+
signing_key:
|
|
76
|
+
specification_version: 4
|
|
77
|
+
summary: NuGet Version Library
|
|
78
|
+
test_files: []
|