semantic 1.2.1 → 1.3.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/lib/semantic.rb +1 -1
- data/lib/semantic/version.rb +41 -2
- data/spec/version_spec.rb +27 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84157e13bb503e4643995ea3fc5e66dc0e669a14
|
4
|
+
data.tar.gz: d66f6977b38924ed245de6b0849c6c6a6f6e48b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a995f1776791066bbd2f46b5bdbab90e0ea53477ea3143ea28d874e41524cdcfa2522a6593f5097f08370b0358b7701a90184f177318596a618fe386400201d
|
7
|
+
data.tar.gz: 6cbe7c9c57700057f807386f6d5df01f51cabcd7197dbb21794614c398bfacb84d041616522f8e90dc7bf608d97d5960781bb81a5321e1717e2171f903adf1c9
|
data/lib/semantic.rb
CHANGED
data/lib/semantic/version.rb
CHANGED
@@ -17,7 +17,7 @@ module Semantic
|
|
17
17
|
end
|
18
18
|
|
19
19
|
|
20
|
-
@major, @minor, @patch = version.split('.').map
|
20
|
+
@major, @minor, @patch = version.split('.').map(&:to_i)
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_a
|
@@ -76,8 +76,48 @@ module Semantic
|
|
76
76
|
(self <=> other_version) == 0
|
77
77
|
end
|
78
78
|
|
79
|
+
def satisfies other_version
|
80
|
+
return true if other_version.strip == '*'
|
81
|
+
parts = other_version.split /(\d(.+)?)/, 2
|
82
|
+
comparator, other_version_string = parts[0].strip, parts[1].strip
|
83
|
+
|
84
|
+
begin
|
85
|
+
Version.new other_version_string
|
86
|
+
comparator.empty? && comparator = '=='
|
87
|
+
satisfies_comparator? comparator, other_version_string
|
88
|
+
rescue ArgumentError
|
89
|
+
if ['<', '>', '<=', '>='].include?(comparator)
|
90
|
+
satisfies_comparator? comparator, pad_version_string(other_version_string)
|
91
|
+
else
|
92
|
+
tilde_matches? other_version_string
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
79
97
|
private
|
80
98
|
|
99
|
+
def pad_version_string version_string
|
100
|
+
parts = version_string.split('.').reject {|x| x == '*'}
|
101
|
+
while parts.length < 3
|
102
|
+
parts << '0'
|
103
|
+
end
|
104
|
+
parts.join '.'
|
105
|
+
end
|
106
|
+
|
107
|
+
def tilde_matches? other_version_string
|
108
|
+
this_parts = to_a.collect &:to_s
|
109
|
+
other_parts = other_version_string.split('.').reject {|x| x == '*'}
|
110
|
+
other_parts == this_parts[0..other_parts.length-1]
|
111
|
+
end
|
112
|
+
|
113
|
+
def satisfies_comparator? comparator, other_version_string
|
114
|
+
if comparator == '~'
|
115
|
+
tilde_matches? other_version_string
|
116
|
+
else
|
117
|
+
self.send comparator, other_version_string
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
81
121
|
def compare_recursively ary1, ary2
|
82
122
|
# Short-circuit the recursion entirely if they're just equal
|
83
123
|
return 0 if ary1 == ary2
|
@@ -105,4 +145,3 @@ module Semantic
|
|
105
145
|
end
|
106
146
|
end
|
107
147
|
end
|
108
|
-
|
data/spec/version_spec.rb
CHANGED
@@ -146,6 +146,33 @@ describe Semantic::Version do
|
|
146
146
|
@v1_5_9_pre_1_build_4352.should == @v1_5_9_pre_1_build_5127
|
147
147
|
@v1_5_9_pre_1_build_4352.should == @v1_5_9_pre_1
|
148
148
|
end
|
149
|
+
|
150
|
+
it "determines whether it satisfies >= style specifications" do
|
151
|
+
@v1_6_0.satisfies('>=1.6.0').should be_true
|
152
|
+
@v1_6_0.satisfies('<=1.6.0').should be_true
|
153
|
+
@v1_6_0.satisfies('>=1.5.0').should be_true
|
154
|
+
@v1_6_0.satisfies('<=1.5.0').should_not be_true
|
155
|
+
|
156
|
+
# partial / non-semver numbers after comparator are extremely common in
|
157
|
+
# version specifications in the wild
|
158
|
+
|
159
|
+
@v1_6_0.satisfies('>1.5').should be_true
|
160
|
+
@v1_6_0.satisfies('<1').should_not be_true
|
161
|
+
end
|
162
|
+
|
163
|
+
it "determines whether it satisfies * style specifications" do
|
164
|
+
@v1_6_0.satisfies('1.*').should be_true
|
165
|
+
@v1_6_0.satisfies('1.6.*').should be_true
|
166
|
+
@v1_6_0.satisfies('2.*').should_not be_true
|
167
|
+
@v1_6_0.satisfies('1.5.*').should_not be_true
|
168
|
+
end
|
169
|
+
|
170
|
+
it "determines whether it satisfies ~ style specifications" do
|
171
|
+
@v1_6_0.satisfies('~1.6').should be_true
|
172
|
+
@v1_5_9_pre_1.satisfies('~1.5').should be_true
|
173
|
+
@v1_6_0.satisfies('~1.5').should_not be_true
|
174
|
+
end
|
175
|
+
|
149
176
|
end
|
150
177
|
|
151
178
|
context "type coercions" do
|
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.3.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-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.1.9
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Semantic Version utility class
|