semantic_range 0.2.0 → 1.0.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: 713091878f31485514b30d0ab9e9f7281576a260
4
- data.tar.gz: 0f6bf36a44b5e9b4a6e61c5e3f42dbd4aeb2f60c
3
+ metadata.gz: cb5291e42f7111e3e2a32c66c9ea3bf647b8476f
4
+ data.tar.gz: c56b165d6e765b0d9360f0ec32cc8bcd8014018a
5
5
  SHA512:
6
- metadata.gz: 201e862b74b02896c79356d61ee4128ae31b35d7ebbd2e2548d028d0fe2294389bcb5b699fdf0e0e70630db19cc21b8f45c535ada00f3ab2bda9111f90c409aa
7
- data.tar.gz: 1c16363476186d8d54f0d2c229f805f962af5afd43eb3cd4de8c7cc954c858b85c08612289d6fc621843124f23280d6c0e9af2d97c8d81a6c0a35ff58f197ca1
6
+ metadata.gz: 94c4fb6189ca2e27813a0a792516c90517456789818626f10a634dcebbf9e53d5eebd6608c5175c38f424f401f42b90fba722fb97fd880c25284a26276e20171
7
+ data.tar.gz: edeaddff9d68446766e4cfda74537d033342c6716054eaf95b663312cc644a616b459abdedfd2bbcbefe1f716edd500ce1c2afa6fd7077efd6f38e235215a295
@@ -46,7 +46,9 @@ module SemanticRange
46
46
  MAX_LENGTH = 256
47
47
 
48
48
  class InvalidIncrement < StandardError; end
49
- class NoMatchFound < StandardError; end
49
+ class InvalidVersion < StandardError; end
50
+ class InvalidComparator < StandardError; end
51
+ class InvalidRange < StandardError; end
50
52
 
51
53
  def self.ltr(version, range, loose = false)
52
54
  outside(version, range, '<', loose)
@@ -151,8 +153,12 @@ module SemanticRange
151
153
  Range.new(range, loose).test(version)
152
154
  end
153
155
 
154
- def self.max_satisfying(version, range, loose = false)
155
- # TODO
156
+ def self.max_satisfying(versions, range, loose = false)
157
+ versions.select { |version|
158
+ satisfies(version, range, loose)
159
+ }.sort { |a, b|
160
+ rcompare(a, b, loose)
161
+ }[0] || nil
156
162
  end
157
163
 
158
164
  def self.valid_range(range, loose = false)
@@ -231,11 +237,7 @@ module SemanticRange
231
237
  rxp = loose ? LOOSE : FULL
232
238
  return nil if !rxp.match(version)
233
239
 
234
- begin
235
- Version.new(version, loose)
236
- rescue
237
- nil
238
- end
240
+ Version.new(version, loose)
239
241
  end
240
242
 
241
243
  def self.increment!(version, release, loose, identifier)
@@ -245,7 +247,7 @@ module SemanticRange
245
247
  end
246
248
 
247
249
  Version.new(version, loose).increment!(release, identifier).version
248
- rescue InvalidIncrement, NoMatchFound
250
+ rescue InvalidIncrement, InvalidVersion
249
251
  nil
250
252
  end
251
253
 
@@ -259,4 +261,10 @@ module SemanticRange
259
261
  return "#{pre}patch" if a.patch != b.patch
260
262
  return "prerelease" if pre_diff
261
263
  end
264
+
265
+ def self.to_comparators(range, loose = false)
266
+ Range.new(range, loose).set.map do |comp|
267
+ comp.map(&:to_s)
268
+ end
269
+ end
262
270
  end
@@ -25,7 +25,7 @@ module SemanticRange
25
25
 
26
26
  def parse(comp)
27
27
  m = comp.match(@loose ? COMPARATORLOOSE : COMPARATOR)
28
- raise "Invalid comparator: #{comp}" unless m
28
+ raise InvalidComparator.new(comp) unless m
29
29
 
30
30
  @operator = m[1]
31
31
  @operator = '' if @operator == '='
@@ -60,5 +60,33 @@ module SemanticRange
60
60
  i += 1
61
61
  end
62
62
  end
63
+
64
+ def last_number_index
65
+ parts.rindex { |e| e.is_a? Fixnum }
66
+ end
67
+
68
+ def increment!(identifier = nil)
69
+ if empty?
70
+ zero!
71
+ else
72
+ if last_number_index
73
+ @parts[last_number_index] += 1
74
+ else
75
+ @parts << 0
76
+ end
77
+ end
78
+
79
+ if identifier
80
+ # 1.2.0-beta.1 bumps to 1.2.0-beta.2,
81
+ # 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
82
+ if parts[0] == identifier
83
+ unless parts[1].kind_of?(Fixnum)
84
+ @parts = [identifier, 0]
85
+ end
86
+ else
87
+ @parts = [identifier, 0]
88
+ end
89
+ end
90
+ end
63
91
  end
64
92
  end
@@ -2,7 +2,7 @@ module SemanticRange
2
2
  class Range
3
3
  attr_reader :loose, :raw, :range, :set
4
4
 
5
- def initialize(range, loose)
5
+ def initialize(range, loose = false)
6
6
  range = range.raw if range.is_a?(Range)
7
7
 
8
8
  @raw = range
@@ -10,9 +10,14 @@ module SemanticRange
10
10
  split = range.split(/\s*\|\|\s*/)
11
11
  split = ['', ''] if range == '||'
12
12
  split = [''] if split == []
13
- @set = split.map {|range| parse_range(range.strip) }
14
13
 
15
- raise 'Invalid SemVer Range: ' + range if @set.empty? || @set == [[]]
14
+ begin
15
+ @set = split.map {|range| parse_range(range.strip) }
16
+ rescue InvalidComparator
17
+ @set = []
18
+ end
19
+
20
+ raise InvalidRange.new(range) if @set.empty? || @set == [[]]
16
21
 
17
22
  format
18
23
  end
@@ -260,7 +265,7 @@ module SemanticRange
260
265
  elsif isX(tm)
261
266
  to = "<#{(tM.to_i + 1)}.0.0"
262
267
  elsif isX(tp)
263
- to = "<#{tm}.#{(tm.to_i + 1)}.0"
268
+ to = "<#{tM}.#{(tm.to_i + 1)}.0"
264
269
  elsif tpr
265
270
  to = "<=#{tM}.#{tm}.#{tp}-#{tpr}"
266
271
  else
@@ -1,5 +1,5 @@
1
1
  module SemanticRange
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
 
4
4
  class Version
5
5
  attr_reader :major, :minor, :patch, :prerelease
@@ -10,9 +10,13 @@ module SemanticRange
10
10
 
11
11
  @raw = version.raw if version.is_a?(Version)
12
12
 
13
- match = @raw.strip.match(loose ? LOOSE : FULL)
13
+ match = @raw.to_s.strip.match(loose ? LOOSE : FULL)
14
14
 
15
- raise NoMatchFound.new(version) if match.nil?
15
+ raise InvalidVersion.new(version) if match.nil?
16
+
17
+ if String(version.to_s).length > MAX_LENGTH
18
+ raise InvalidVersion.new("#{version} is too long")
19
+ end
16
20
 
17
21
  @major = match[1] ? match[1].to_i : 0
18
22
  @minor = match[2] ? match[2].to_i : 0
@@ -140,35 +144,7 @@ module SemanticRange
140
144
  # This probably shouldn't be used publicly.
141
145
  # 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
142
146
  when 'pre'
143
- if @prerelease.empty?
144
- @prerelease.zero!
145
- else
146
- parts = @prerelease.parts
147
- i = parts.length
148
- while i >= 0
149
- if parts[i].is_a?(Fixnum)
150
- parts[i] += 1
151
- i = -2
152
- else
153
- i = i-1
154
- end
155
- end
156
- if i == -1 # didn't increment anything
157
- parts << 0
158
- end
159
- @prerelease = PreRelease.new(parts.join("."))
160
- end
161
- if identifier
162
- # 1.2.0-beta.1 bumps to 1.2.0-beta.2,
163
- # 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
164
- if @prerelease.parts[0] == identifier
165
- unless @prerelease.parts[1].kind_of?(Fixnum)
166
- @prerelease = PreRelease.new([identifier, 0].join('.'))
167
- end
168
- else
169
- @prerelease = PreRelease.new([identifier, 0].join('.'))
170
- end
171
- end
147
+ @prerelease.increment!(identifier)
172
148
  else
173
149
  raise InvalidIncrement.new release
174
150
  end
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.10"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "rake", "~> 10.4"
23
+ spec.add_development_dependency "rspec", "~> 3.4"
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_range
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '10.4'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '10.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.4'
55
55
  description:
56
56
  email:
57
57
  - andrewnez@gmail.com