semantic 1.1.1 → 1.2.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/README.md +1 -1
- data/lib/semantic/version.rb +83 -72
- data/lib/semantic.rb +1 -1
- data/spec/version_spec.rb +60 -30
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 587cd43a2f134032a864c84337c0207c3e8e495d
|
4
|
+
data.tar.gz: c7d7e9475f392a1c57b2567fa89b021edd5b4c73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1f6fa899e311d1bc4de8d82271e30621cdc16cd65224dcc6c3b690564d9471a6c02ce89800f5aeed23d49efeccf9ae2ccef80abbcff0325587387a0d4dc47f9
|
7
|
+
data.tar.gz: cce04f83bb307dfc73f65968c3d73aaf1420963c1bac84e3964460ea4adb7f25857ce10ba78e4ac540542a35444b17715be7cd873e244a99aec9a3825432044c
|
data/README.md
CHANGED
data/lib/semantic/version.rb
CHANGED
@@ -1,97 +1,108 @@
|
|
1
1
|
# See: http://semver.org
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def initialize version_str
|
7
|
-
raise ArgumentError.new("Not a valid SemVer Version (http://semver.org)") unless version_str =~ SemVerRegexp
|
8
|
-
|
9
|
-
version, parts = version_str.split '-'
|
10
|
-
if not parts.nil? and parts.include? '+'
|
11
|
-
@pre, @build = parts.split '+'
|
12
|
-
elsif version.include? '+'
|
13
|
-
version, @build = version.split '+'
|
14
|
-
else
|
15
|
-
@pre = parts
|
16
|
-
end
|
2
|
+
module Semantic
|
3
|
+
class Version
|
4
|
+
SemVerRegexp = /^(\d+\.\d+\.\d+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$/
|
5
|
+
attr_accessor :major, :minor, :patch, :pre, :build
|
17
6
|
|
7
|
+
def initialize version_str
|
8
|
+
raise ArgumentError.new("#{version_str} is not a valid SemVer Version (http://semver.org)") unless version_str =~ SemVerRegexp
|
18
9
|
|
19
|
-
|
20
|
-
|
10
|
+
version, parts = version_str.split '-'
|
11
|
+
if not parts.nil? and parts.include? '+'
|
12
|
+
@pre, @build = parts.split '+'
|
13
|
+
elsif version.include? '+'
|
14
|
+
version, @build = version.split '+'
|
15
|
+
else
|
16
|
+
@pre = parts
|
17
|
+
end
|
21
18
|
|
22
|
-
def to_a
|
23
|
-
[@major, @minor, @patch, @pre, @build]
|
24
|
-
end
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
str << '-' << @pre unless @pre.nil?
|
29
|
-
str << '+' << @build unless @build.nil?
|
20
|
+
@major, @minor, @patch = version.split('.').map &:to_i
|
21
|
+
end
|
30
22
|
|
31
|
-
|
32
|
-
|
23
|
+
def to_a
|
24
|
+
[@major, @minor, @patch, @pre, @build]
|
25
|
+
end
|
33
26
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
27
|
+
def to_s
|
28
|
+
str = [@major, @minor, @patch].join '.'
|
29
|
+
str << '-' << @pre unless @pre.nil?
|
30
|
+
str << '+' << @build unless @build.nil?
|
38
31
|
|
39
|
-
|
40
|
-
|
41
|
-
alias to_string to_s
|
32
|
+
str
|
33
|
+
end
|
42
34
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
35
|
+
def to_h
|
36
|
+
keys = [:major, :minor, :patch, :pre, :build]
|
37
|
+
Hash[keys.zip(self.to_a)]
|
38
|
+
end
|
47
39
|
|
48
|
-
|
49
|
-
|
50
|
-
|
40
|
+
alias to_hash to_h
|
41
|
+
alias to_array to_a
|
42
|
+
alias to_string to_s
|
51
43
|
|
52
|
-
|
53
|
-
|
54
|
-
end
|
44
|
+
def <=> other_version
|
45
|
+
other_version = Version.new(other_version) if other_version.is_a? String
|
55
46
|
|
56
|
-
|
57
|
-
|
58
|
-
end
|
47
|
+
v1 = self.dup
|
48
|
+
v2 = other_version.dup
|
59
49
|
|
60
|
-
|
61
|
-
|
62
|
-
|
50
|
+
# The build must be excluded from the comparison, so that e.g. 1.2.3+foo and 1.2.3+bar are semantically equal.
|
51
|
+
# "Build metadata SHOULD be ignored when determining version precedence".
|
52
|
+
# (SemVer 2.0.0-rc.2, paragraph 10 - http://www.semver.org)
|
53
|
+
v1.build = nil
|
54
|
+
v2.build = nil
|
63
55
|
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
56
|
+
compare_recursively(v1.to_a, v2.to_a)
|
57
|
+
end
|
69
58
|
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
def > other_version
|
60
|
+
(self <=> other_version) == 1
|
61
|
+
end
|
73
62
|
|
74
|
-
|
63
|
+
def < other_version
|
64
|
+
(self <=> other_version) == -1
|
65
|
+
end
|
75
66
|
|
76
|
-
|
77
|
-
|
67
|
+
def >= other_version
|
68
|
+
(self <=> other_version) >= 0
|
69
|
+
end
|
78
70
|
|
79
|
-
|
80
|
-
|
81
|
-
return -1
|
82
|
-
elsif not a.nil? and b.nil?
|
83
|
-
return 1
|
71
|
+
def <= other_version
|
72
|
+
(self <=> other_version) <= 0
|
84
73
|
end
|
85
74
|
|
86
|
-
|
87
|
-
|
88
|
-
return 1
|
89
|
-
elsif a < b
|
90
|
-
return -1
|
75
|
+
def == other_version
|
76
|
+
(self <=> other_version) == 0
|
91
77
|
end
|
92
78
|
|
93
|
-
|
94
|
-
|
79
|
+
private
|
80
|
+
|
81
|
+
def compare_recursively ary1, ary2
|
82
|
+
# Short-circuit the recursion entirely if they're just equal
|
83
|
+
return 0 if ary1 == ary2
|
84
|
+
|
85
|
+
a = ary1.shift; b = ary2.shift
|
86
|
+
|
87
|
+
# Reached the end of the arrays, equal all the way down
|
88
|
+
return 0 if a.nil? and b.nil?
|
89
|
+
|
90
|
+
# Mismatched types (ie. one has a pre and the other doesn't)
|
91
|
+
if a.nil? and not b.nil?
|
92
|
+
return 1
|
93
|
+
elsif not a.nil? and b.nil?
|
94
|
+
return -1
|
95
|
+
end
|
96
|
+
|
97
|
+
if a < b
|
98
|
+
return -1
|
99
|
+
elsif a > b
|
100
|
+
return 1
|
101
|
+
end
|
102
|
+
|
103
|
+
# Versions are equal thus far, so recurse down to the next part.
|
104
|
+
compare_recursively ary1, ary2
|
105
|
+
end
|
95
106
|
end
|
96
107
|
end
|
97
108
|
|
data/lib/semantic.rb
CHANGED
data/spec/version_spec.rb
CHANGED
@@ -67,53 +67,83 @@ describe Semantic::Version do
|
|
67
67
|
|
68
68
|
context "comparisons" do
|
69
69
|
before(:each) do
|
70
|
-
|
71
|
-
@
|
72
|
-
@
|
73
|
-
@
|
70
|
+
# These three are all semantically equivalent, according to the spec.
|
71
|
+
@v1_5_9_pre_1 = Semantic::Version.new '1.5.9-pre.1'
|
72
|
+
@v1_5_9_pre_1_build_5127 = Semantic::Version.new '1.5.9-pre.1+build.5127'
|
73
|
+
@v1_5_9_pre_1_build_4352 = Semantic::Version.new '1.5.9-pre.1+build.4352'
|
74
|
+
|
75
|
+
@v1_5_9 = Semantic::Version.new '1.5.9'
|
76
|
+
@v1_6_0 = Semantic::Version.new '1.6.0'
|
74
77
|
end
|
75
78
|
|
76
79
|
it "determines sort order" do
|
77
|
-
|
78
|
-
(@
|
79
|
-
|
80
|
-
(@
|
81
|
-
(@
|
80
|
+
# The second parameter here can be a string, so we want to ensure that this kind of comparison works also.
|
81
|
+
(@v1_5_9_pre_1 <=> @v1_5_9_pre_1.to_s).should == 0
|
82
|
+
|
83
|
+
(@v1_5_9_pre_1 <=> @v1_5_9_pre_1_build_5127).should == 0
|
84
|
+
(@v1_5_9_pre_1 <=> @v1_5_9).should == -1
|
85
|
+
(@v1_5_9_pre_1_build_5127 <=> @v1_5_9).should == -1
|
86
|
+
|
87
|
+
@v1_5_9_pre_1_build_5127.build.should == 'build.5127'
|
82
88
|
|
83
|
-
|
89
|
+
(@v1_5_9 <=> @v1_5_9).should == 0
|
90
|
+
|
91
|
+
(@v1_5_9 <=> @v1_6_0).should == -1
|
92
|
+
(@v1_6_0 <=> @v1_5_9).should == 1
|
93
|
+
(@v1_6_0 <=> @v1_5_9_pre_1).should == 1
|
94
|
+
(@v1_5_9_pre_1 <=> @v1_6_0).should == -1
|
95
|
+
|
96
|
+
[@v1_5_9_pre_1, @v1_5_9_pre_1_build_5127, @v1_5_9, @v1_6_0]
|
97
|
+
.reverse
|
98
|
+
.sort
|
99
|
+
.should == [@v1_5_9_pre_1, @v1_5_9_pre_1_build_5127, @v1_5_9, @v1_6_0]
|
84
100
|
end
|
85
101
|
|
86
102
|
it "determines whether it is greater than another instance" do
|
87
|
-
|
88
|
-
|
89
|
-
@
|
90
|
-
@
|
103
|
+
# These should be equal, since "Build metadata SHOULD be ignored when determining version precedence".
|
104
|
+
# (SemVer 2.0.0-rc.2, paragraph 10 - http://www.semver.org)
|
105
|
+
@v1_5_9_pre_1.should_not > @v1_5_9_pre_1_build_5127
|
106
|
+
@v1_5_9_pre_1.should_not < @v1_5_9_pre_1_build_5127
|
107
|
+
|
108
|
+
@v1_6_0.should > @v1_5_9
|
109
|
+
@v1_5_9.should_not > @v1_6_0
|
110
|
+
@v1_5_9.should > @v1_5_9_pre_1_build_5127
|
111
|
+
@v1_5_9.should > @v1_5_9_pre_1
|
91
112
|
end
|
92
113
|
|
93
|
-
it "determines whether it is less than another
|
94
|
-
@
|
95
|
-
@
|
96
|
-
@
|
97
|
-
@
|
114
|
+
it "determines whether it is less than another instance" do
|
115
|
+
@v1_5_9_pre_1.should_not < @v1_5_9_pre_1_build_5127
|
116
|
+
@v1_5_9_pre_1_build_5127.should_not < @v1_5_9_pre_1
|
117
|
+
@v1_5_9_pre_1.should < @v1_5_9
|
118
|
+
@v1_5_9_pre_1.should < @v1_6_0
|
119
|
+
@v1_5_9_pre_1_build_5127.should < @v1_6_0
|
120
|
+
@v1_5_9.should < @v1_6_0
|
98
121
|
end
|
99
122
|
|
100
123
|
it "determines whether it is greater than or equal to another instance" do
|
101
|
-
@
|
102
|
-
@
|
103
|
-
@
|
104
|
-
@
|
124
|
+
@v1_5_9_pre_1.should >= @v1_5_9_pre_1
|
125
|
+
@v1_5_9_pre_1.should >= @v1_5_9_pre_1_build_5127
|
126
|
+
@v1_5_9_pre_1_build_5127.should >= @v1_5_9_pre_1
|
127
|
+
@v1_5_9.should >= @v1_5_9_pre_1
|
128
|
+
@v1_6_0.should >= @v1_5_9
|
129
|
+
@v1_5_9_pre_1_build_5127.should_not >= @v1_6_0
|
105
130
|
end
|
106
131
|
|
107
132
|
it "determines whether it is less than or equal to another instance" do
|
108
|
-
@
|
109
|
-
@
|
110
|
-
@
|
111
|
-
@
|
133
|
+
@v1_5_9_pre_1.should <= @v1_5_9_pre_1_build_5127
|
134
|
+
@v1_6_0.should_not <= @v1_5_9
|
135
|
+
@v1_5_9_pre_1_build_5127.should <= @v1_5_9_pre_1_build_5127
|
136
|
+
@v1_5_9.should_not <= @v1_5_9_pre_1
|
112
137
|
end
|
113
138
|
|
114
|
-
it "determines whether it is
|
115
|
-
@
|
116
|
-
@
|
139
|
+
it "determines whether it is semantically equal to another instance" do
|
140
|
+
@v1_5_9_pre_1.should == @v1_5_9_pre_1.dup
|
141
|
+
@v1_5_9_pre_1_build_5127.should == @v1_5_9_pre_1_build_5127.dup
|
142
|
+
|
143
|
+
# "Semantically equal" is the keyword here; these are by definition not "equal" (different build), but should be treated as
|
144
|
+
# equal according to the spec.
|
145
|
+
@v1_5_9_pre_1_build_4352.should == @v1_5_9_pre_1_build_5127
|
146
|
+
@v1_5_9_pre_1_build_4352.should == @v1_5_9_pre_1
|
117
147
|
end
|
118
148
|
end
|
119
149
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lindsey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -82,3 +82,4 @@ test_files:
|
|
82
82
|
- spec/core_ext_spec.rb
|
83
83
|
- spec/spec_helper.rb
|
84
84
|
- spec/version_spec.rb
|
85
|
+
has_rdoc:
|