semantic 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25912a3ae732b9bee108db7982c3c32a8970579c
4
- data.tar.gz: fcd186042df03126f0318442f62e8eccc0b726d6
3
+ metadata.gz: 6b0d05c7bf684f53e2868af8b7ef4d10b4e32147
4
+ data.tar.gz: 2b056bdd6e59fd70c009ec240a486eecc1be6ce4
5
5
  SHA512:
6
- metadata.gz: b3bf5332d05f69d77d1e04889d2782b201c8c8e1215854abcf5c695cf46793bcf013f5c901707683429989585c155f1111bcd0ad55504db3f865ffbdc1de6636
7
- data.tar.gz: 3bedeefba2d4579b5bc262f9b09efa2b7ab625b4b715feb6059f93fced4661632ca037d62686da05c4f2f0527f07bbefd80ee2ae47cb835c0675ccf37b3637d1
6
+ metadata.gz: 20af7df4c207994a636249361d917e84cd63429c1e2423a53899632bc8fcd65ebdc89c6f785ab2476260db2bac94f35cdb7809687af0b2bd76705fb9a955398e
7
+ data.tar.gz: 442ba8444462357df0fe5e40baef7225de789da8c518c1309d521e89f5d83b0eb5890871828f859945695c1ec77c77d0b00b456c6249a252260c4c244d402211
@@ -1,4 +1,4 @@
1
1
  module Semantic
2
- GEM_VERSION = '1.5.0'
2
+ GEM_VERSION = '1.6.0'
3
3
  autoload :Version, 'semantic/version'
4
4
  end
@@ -1,6 +1,8 @@
1
1
  # See: http://semver.org
2
2
  module Semantic
3
3
  class Version
4
+ include Comparable
5
+
4
6
  SemVerRegexp = /\A(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?\Z/
5
7
 
6
8
 
@@ -88,27 +90,7 @@ module Semantic
88
90
  return compare_pre(self.pre, other_version.pre)
89
91
  end
90
92
 
91
- def > other_version
92
- (self <=> other_version) == 1
93
- end
94
-
95
- def < other_version
96
- (self <=> other_version) == -1
97
- end
98
-
99
- def >= other_version
100
- (self <=> other_version) >= 0
101
- end
102
-
103
- def <= other_version
104
- (self <=> other_version) <= 0
105
- end
106
-
107
- def == other_version
108
- (self <=> other_version) == 0
109
- end
110
-
111
- def satisfies other_version
93
+ def satisfies? other_version
112
94
  return true if other_version.strip == '*'
113
95
  parts = other_version.split(/(\d(.+)?)/, 2)
114
96
  comparator, other_version_string = parts[0].strip, parts[1].strip
@@ -120,12 +102,19 @@ module Semantic
120
102
  rescue ArgumentError
121
103
  if ['<', '>', '<=', '>='].include?(comparator)
122
104
  satisfies_comparator? comparator, pad_version_string(other_version_string)
105
+ elsif comparator == '~>'
106
+ pessimistic_match? other_version_string
123
107
  else
124
108
  tilde_matches? other_version_string
125
109
  end
126
110
  end
127
111
  end
128
112
 
113
+ def satisfied_by? versions
114
+ raise ArgumentError.new("Versions #{versions} should be an array of versions") unless versions.is_a? Array
115
+ versions.all? { |version| satisfies?(version) }
116
+ end
117
+
129
118
  [:major, :minor, :patch].each do |term|
130
119
  define_method("#{term}!") { increment!(term) }
131
120
  end
@@ -159,13 +148,32 @@ module Semantic
159
148
  other_parts == this_parts[0..other_parts.length-1]
160
149
  end
161
150
 
151
+ def pessimistic_match? other_version_string
152
+ other_parts = other_version_string.split('.')
153
+ unless other_parts.size == 2 || other_parts.size == 3
154
+ raise ArgumentError.new("Version #{other_version_string} should not be applied with a pessimistic operator")
155
+ end
156
+ other_parts.pop
157
+ other_parts << (other_parts.pop.to_i + 1).to_s
158
+ satisfies_comparator?('>=', semverified(other_version_string)) && satisfies_comparator?('<', semverified(other_parts.join('.')))
159
+ end
160
+
162
161
  def satisfies_comparator? comparator, other_version_string
163
162
  if comparator == '~'
164
163
  tilde_matches? other_version_string
164
+ elsif comparator == '~>'
165
+ pessimistic_match? other_version_string
165
166
  else
166
167
  self.send comparator, other_version_string
167
168
  end
168
169
  end
169
170
 
171
+ def semverified version_string
172
+ parts = version_string.split('.')
173
+ raise ArgumentError.new("Version #{version_string} not supported by semverified") if parts.size > 3
174
+ (3 - parts.size).times { parts << '0' }
175
+ parts.join('.')
176
+ end
177
+
170
178
  end
171
179
  end
@@ -181,30 +181,76 @@ describe Semantic::Version do
181
181
  expect(@v1_5_9_pre_1_build_4352).to eq(@v1_5_9_pre_1)
182
182
  end
183
183
 
184
+ it 'determines whether it is between two others instance' do
185
+ expect(@v1_5_9).to be_between @v1_5_9_pre_1, @v1_6_0
186
+ expect(@v1_5_9).to_not be_between @v1_6_0, @v1_6_0_beta
187
+ end
188
+
184
189
  it 'determines whether it satisfies >= style specifications' do
185
- expect(@v1_6_0.satisfies('>=1.6.0')).to be true
186
- expect(@v1_6_0.satisfies('<=1.6.0')).to be true
187
- expect(@v1_6_0.satisfies('>=1.5.0')).to be true
188
- expect(@v1_6_0.satisfies('<=1.5.0')).not_to be true
190
+ expect(@v1_6_0.satisfies?('>=1.6.0')).to be true
191
+ expect(@v1_6_0.satisfies?('<=1.6.0')).to be true
192
+ expect(@v1_6_0.satisfies?('>=1.5.0')).to be true
193
+ expect(@v1_6_0.satisfies?('<=1.5.0')).not_to be true
189
194
 
190
195
  # partial / non-semver numbers after comparator are extremely common in
191
196
  # version specifications in the wild
192
197
 
193
- expect(@v1_6_0.satisfies('>1.5')).to be true
194
- expect(@v1_6_0.satisfies('<1')).not_to be true
198
+ expect(@v1_6_0.satisfies?('>1.5')).to be true
199
+ expect(@v1_6_0.satisfies?('<1')).not_to be true
195
200
  end
196
201
 
197
202
  it 'determines whether it satisfies * style specifications' do
198
- expect(@v1_6_0.satisfies('1.*')).to be true
199
- expect(@v1_6_0.satisfies('1.6.*')).to be true
200
- expect(@v1_6_0.satisfies('2.*')).not_to be true
201
- expect(@v1_6_0.satisfies('1.5.*')).not_to be true
203
+ expect(@v1_6_0.satisfies?('1.*')).to be true
204
+ expect(@v1_6_0.satisfies?('1.6.*')).to be true
205
+ expect(@v1_6_0.satisfies?('2.*')).not_to be true
206
+ expect(@v1_6_0.satisfies?('1.5.*')).not_to be true
202
207
  end
203
208
 
204
209
  it 'determines whether it satisfies ~ style specifications' do
205
- expect(@v1_6_0.satisfies('~1.6')).to be true
206
- expect(@v1_5_9_pre_1.satisfies('~1.5')).to be true
207
- expect(@v1_6_0.satisfies('~1.5')).not_to be true
210
+ expect(@v1_6_0.satisfies?('~1.6')).to be true
211
+ expect(@v1_5_9_pre_1.satisfies?('~1.5')).to be true
212
+ expect(@v1_6_0.satisfies?('~1.5')).not_to be true
213
+ end
214
+
215
+ it 'determines whether it satisfies ~> style specifications' do
216
+ expect(@v1_5_9_pre_1_build_5127.satisfies?('~> 1.4')).to be true
217
+ expect(@v1_5_9_pre_1_build_4352.satisfies?('~> 1.5.2')).to be true
218
+ expect(@v1_6_0_alpha_1.satisfies?('~> 1.4')).to be true
219
+
220
+ expect(@v1_5_9.satisfies?('~> 1.0')).to be true
221
+ expect(@v1_5_9.satisfies?('~> 1.4')).to be true
222
+ expect(Semantic::Version.new('1.99.1').satisfies?('~> 1.5')).to be true
223
+ expect(@v1_5_9.satisfies?('~> 1.5')).to be true
224
+ expect(@v1_5_9.satisfies?('~> 1.5.0')).to be true
225
+ expect(@v1_5_9.satisfies?('~> 1.5.8')).to be true
226
+ expect(@v1_5_9.satisfies?('~> 1.5.9')).to be true
227
+ expect(Semantic::Version.new('1.5.99').satisfies?('~> 1.5.9')).to be true
228
+ expect(@v1_5_9.satisfies?('~> 1.6.0')).to be false
229
+ expect(@v1_5_9.satisfies?('~> 1.6')).to be false
230
+ expect(@v1_5_9.satisfies?('~> 1.7')).to be false
231
+ end
232
+
233
+ it 'determines whether version is satisfies by range of bound versions' do
234
+ v5_2_1 = Semantic::Version.new('5.2.1')
235
+ v5_3_0 = Semantic::Version.new('5.3.0')
236
+ v6_0_1 = Semantic::Version.new('6.0.1')
237
+ range = [
238
+ ">= 5.2.1",
239
+ "<= 6.0.0"
240
+ ]
241
+
242
+ expect(v5_2_1.satisfied_by?(range)).to be true
243
+ expect(v5_3_0.satisfied_by?(range)).to be true
244
+ expect(v6_0_1.satisfied_by?(range)).to be false
245
+ end
246
+
247
+ it 'raises error if the input is not an array of versions' do
248
+ v5_2_1 = Semantic::Version.new('5.2.1')
249
+ range = ">= 5.2.1 <= 6.0.0"
250
+ expect { v5_2_1.satisfied_by?(range) }.to raise_error(
251
+ ArgumentError,
252
+ /should be an array of versions/
253
+ )
208
254
  end
209
255
  end
210
256
 
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.5.0
4
+ version: 1.6.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: 2016-11-08 00:00:00.000000000 Z
11
+ date: 2017-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -41,7 +41,7 @@ dependencies:
41
41
  description: 'Semantic Version utility class for parsing, storing, and comparing versions.
42
42
  See: http://semver.org'
43
43
  email:
44
- - josh@core-apps.com
44
+ - joshua.s.lindsey@gmail.com
45
45
  executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []