semantic_range 2.3.1 → 3.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
  SHA256:
3
- metadata.gz: ccde626c1a653687b8994fa8f79db2862c424e785e5f9947081481eadce45a21
4
- data.tar.gz: d73b3387a5955017d9133f41a9ab844fb647805d206f1b5221e82ace813c68fb
3
+ metadata.gz: 67ae11bb60e5aa3341d7d83eae4e7f100262878f2ef6612391b4e18ce3ee5801
4
+ data.tar.gz: d25d1b605ddf68eed7979808d0ce1bebbaac5e7025e47ac9d81564dbabb21ca6
5
5
  SHA512:
6
- metadata.gz: df892019675f0bd4c9b0d9e38dbc373201de7b7ee1a5e40f0aa0f6339d7915021476b01569aaa6e2ab4a903fa45c5fc6fa31449877a221be90bf155b6b2e7527
7
- data.tar.gz: ca56913a665bc5b9adca0f5497331c11c190149ca1f6349fdc370f4fe4405cced341a19c95b991ded906fc6edd123022dbfd88aabbfef94f2637bde85c49410b
6
+ metadata.gz: 873719a7f9a4af750cd6deda9a59a7953566d87558f3c7b9825cb3001f188d6453dfca58ce429fb013ffe664ea1806ebefbd081c4c2eadfee734e87dc1d167cf
7
+ data.tar.gz: dff74a1adac2232a3425e6e6d9b7de0412dadd574a3dee8a114d008b9a003c9070db6a69444142980e16e7c7586f7d50f409769e616b18c298b47fb8ce25877d
data/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  [node-semver](https://github.com/npm/node-semver) written in Ruby for comparison and inclusion of semantic versions and ranges.
4
4
 
5
+ **NOTE: current `master` and releases `>= 3` use keyword arguments instead of positional arguments to pass options.
6
+ If you used `SemanticRange.compare(a, b, true)` in SemanticRange 2, in SemanticRange 3 use `SemanticRange.compare(a, b, loose: true)`**
7
+
8
+
9
+
5
10
  ## Installation
6
11
 
7
12
  Add this line to your application's Gemfile:
@@ -30,6 +35,14 @@ SemanticRange.gt?('1.2.3', '9.8.7') # false
30
35
  SemanticRange.lt?('1.2.3', '9.8.7') # true
31
36
  ```
32
37
 
38
+ ### Options
39
+ All functions support optional keyword arguments that modify default behavior. The options supported are:
40
+ * `loose` Be more forgiving about not-quite-valid semver strings. Any resulting output will always be 100% strict compliant. `false` by default.
41
+
42
+ Some functions support `platform` option:
43
+ * `platform` Changes behavior for `'Rubygems'` and `'Packagist'`. `nil` by default. See https://github.com/librariesio/semantic_range/issues/59
44
+
45
+
33
46
  ## Development
34
47
 
35
48
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -38,7 +51,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
38
51
 
39
52
  ## Contributing
40
53
 
41
- Bug reports and pull requests are welcome on GitHub at https://github.com/librariesio/semantic_range. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/librariesio/semantic_range. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://www.contributor-covenant.org/) code of conduct.
42
55
 
43
56
 
44
57
  ## License
@@ -50,15 +50,15 @@ module SemanticRange
50
50
  class InvalidComparator < StandardError; end
51
51
  class InvalidRange < StandardError; end
52
52
 
53
- def self.ltr?(version, range, loose = false, platform = nil)
54
- outside?(version, range, '<', loose, platform)
53
+ def self.ltr?(version, range, loose: false, platform: nil)
54
+ outside?(version, range, '<', loose: loose, platform: platform)
55
55
  end
56
56
 
57
- def self.gtr?(version, range, loose = false, platform = nil)
58
- outside?(version, range, '>', loose, platform)
57
+ def self.gtr?(version, range, loose: false, platform: nil)
58
+ outside?(version, range, '>', loose: loose, platform: platform)
59
59
  end
60
60
 
61
- def self.cmp(a, op, b, loose = false)
61
+ def self.cmp(a, op, b, loose: false)
62
62
  case op
63
63
  when '==='
64
64
  a = a.version if !a.is_a?(String)
@@ -69,27 +69,27 @@ module SemanticRange
69
69
  b = b.version if !b.is_a?(String)
70
70
  a != b
71
71
  when '', '=', '=='
72
- eq?(a, b, loose)
72
+ eq?(a, b, loose: loose)
73
73
  when '!='
74
- neq?(a, b, loose)
74
+ neq?(a, b, loose: loose)
75
75
  when '>'
76
- gt?(a, b, loose)
76
+ gt?(a, b, loose: loose)
77
77
  when '>='
78
- gte?(a, b, loose)
78
+ gte?(a, b, loose: loose)
79
79
  when '<'
80
- lt?(a, b, loose)
80
+ lt?(a, b, loose: loose)
81
81
  when '<='
82
- lte?(a, b, loose)
82
+ lte?(a, b, loose: loose)
83
83
  else
84
84
  raise 'Invalid operator: ' + op
85
85
  end
86
86
  end
87
87
 
88
- def self.outside?(version, range, hilo, loose = false, platform = nil)
89
- version = Version.new(version, loose)
90
- range = Range.new(range, loose, platform)
88
+ def self.outside?(version, range, hilo, loose: false, platform: nil)
89
+ version = Version.new(version, loose: loose)
90
+ range = Range.new(range, loose: loose, platform: platform)
91
91
 
92
- return false if satisfies?(version, range, loose, platform)
92
+ return false if satisfies?(version, range, loose: loose, platform: platform)
93
93
 
94
94
  case hilo
95
95
  when '>'
@@ -114,15 +114,15 @@ module SemanticRange
114
114
 
115
115
  case hilo
116
116
  when '>'
117
- if gt?(comparator.semver, high.semver, loose)
117
+ if gt?(comparator.semver, high.semver, loose: loose)
118
118
  high = comparator
119
- elsif lt?(comparator.semver, low.semver, loose)
119
+ elsif lt?(comparator.semver, low.semver, loose: loose)
120
120
  low = comparator
121
121
  end
122
122
  when '<'
123
- if lt?(comparator.semver, high.semver, loose)
123
+ if lt?(comparator.semver, high.semver, loose: loose)
124
124
  high = comparator
125
- elsif gt?(comparator.semver, low.semver, loose)
125
+ elsif gt?(comparator.semver, low.semver, loose: loose)
126
126
  low = comparator
127
127
  end
128
128
  end
@@ -132,15 +132,15 @@ module SemanticRange
132
132
 
133
133
  case hilo
134
134
  when '>'
135
- if (low.operator.empty? || low.operator == comp) && lte?(version, low.semver, loose)
135
+ if (low.operator.empty? || low.operator == comp) && lte?(version, low.semver, loose: loose)
136
136
  return false;
137
- elsif (low.operator == ecomp && lt?(version, low.semver, loose))
137
+ elsif (low.operator == ecomp && lt?(version, low.semver, loose: loose))
138
138
  return false;
139
139
  end
140
140
  when '<'
141
- if (low.operator.empty? || low.operator == comp) && gte?(version, low.semver, loose)
141
+ if (low.operator.empty? || low.operator == comp) && gte?(version, low.semver, loose: loose)
142
142
  return false;
143
- elsif low.operator == ecomp && gt?(version, low.semver, loose)
143
+ elsif low.operator == ecomp && gt?(version, low.semver, loose: loose)
144
144
  return false;
145
145
  end
146
146
  end
@@ -148,28 +148,28 @@ module SemanticRange
148
148
  true
149
149
  end
150
150
 
151
- def self.satisfies?(version, range, loose = false, platform = nil)
152
- return false if !valid_range(range, loose, platform)
153
- Range.new(range, loose, platform).test(version)
151
+ def self.satisfies?(version, range, loose: false, platform: nil)
152
+ return false if !valid_range(range, loose: loose, platform: platform)
153
+ Range.new(range, loose: loose, platform: platform).test(version)
154
154
  end
155
155
 
156
- def self.filter(versions, range, loose = false, platform = nil)
157
- return [] if !valid_range(range, loose, platform)
156
+ def self.filter(versions, range, loose: false, platform: nil)
157
+ return [] if !valid_range(range, loose: loose, platform: platform)
158
158
 
159
- versions.filter { |v| SemanticRange.satisfies?(v, range, loose, platform) }
159
+ versions.filter { |v| SemanticRange.satisfies?(v, range, loose: loose, platform: platform) }
160
160
  end
161
161
 
162
- def self.max_satisfying(versions, range, loose = false, platform = nil)
162
+ def self.max_satisfying(versions, range, loose: false, platform: nil)
163
163
  versions.select { |version|
164
- satisfies?(version, range, loose, platform)
164
+ satisfies?(version, range, loose: loose, platform: platform)
165
165
  }.sort { |a, b|
166
- rcompare(a, b, loose)
166
+ rcompare(a, b, loose: loose)
167
167
  }[0] || nil
168
168
  end
169
169
 
170
- def self.valid_range(range, loose = false, platform = nil)
170
+ def self.valid_range(range, loose: false, platform: nil)
171
171
  begin
172
- r = Range.new(range, loose, platform).range
172
+ r = Range.new(range, loose: loose, platform: platform).range
173
173
  r = '*' if r.nil? || r.empty?
174
174
  r
175
175
  rescue
@@ -177,61 +177,61 @@ module SemanticRange
177
177
  end
178
178
  end
179
179
 
180
- def self.compare(a, b, loose = false)
181
- Version.new(a, loose).compare(b)
180
+ def self.compare(a, b, loose: false)
181
+ Version.new(a, loose: loose).compare(b)
182
182
  end
183
183
 
184
184
  def self.compare_loose(a, b)
185
- compare(a, b, true)
185
+ compare(a, b, loose: true)
186
186
  end
187
187
 
188
- def self.rcompare(a, b, loose = false)
189
- compare(b, a, true)
188
+ def self.rcompare(a, b, loose: false)
189
+ compare(b, a, loose: true)
190
190
  end
191
191
 
192
- def self.sort(list, loose = false)
192
+ def self.sort(list, loose: false)
193
193
  # TODO
194
194
  end
195
195
 
196
- def self.rsort(list, loose = false)
196
+ def self.rsort(list, loose: false)
197
197
  # TODO
198
198
  end
199
199
 
200
- def self.lt?(a, b, loose = false)
201
- compare(a, b, loose) < 0
200
+ def self.lt?(a, b, loose: false)
201
+ compare(a, b, loose: loose) < 0
202
202
  end
203
203
 
204
- def self.gt?(a, b, loose = false)
205
- compare(a, b, loose) > 0
204
+ def self.gt?(a, b, loose: false)
205
+ compare(a, b, loose: loose) > 0
206
206
  end
207
207
 
208
- def self.eq?(a, b, loose = false)
209
- compare(a, b, loose) == 0
208
+ def self.eq?(a, b, loose: false)
209
+ compare(a, b, loose: loose) == 0
210
210
  end
211
211
 
212
- def self.neq?(a, b, loose = false)
213
- compare(a, b, loose) != 0
212
+ def self.neq?(a, b, loose: false)
213
+ compare(a, b, loose: loose) != 0
214
214
  end
215
215
 
216
- def self.gte?(a, b, loose = false)
217
- compare(a, b, loose) >= 0
216
+ def self.gte?(a, b, loose: false)
217
+ compare(a, b, loose: loose) >= 0
218
218
  end
219
219
 
220
- def self.lte?(a, b, loose = false)
221
- compare(a, b, loose) <= 0
220
+ def self.lte?(a, b, loose: false)
221
+ compare(a, b, loose: loose) <= 0
222
222
  end
223
223
 
224
- def self.valid(version, loose = false)
225
- v = parse(version, loose)
224
+ def self.valid(version, loose: false)
225
+ v = parse(version, loose: loose)
226
226
  return v ? v.version : nil
227
227
  end
228
228
 
229
- def self.clean(version, loose = false)
230
- s = parse(version.strip.gsub(/^[=v]+/, ''), loose)
229
+ def self.clean(version, loose: false)
230
+ s = parse(version.strip.gsub(/^[=v]+/, ''), loose: loose)
231
231
  return s ? s.version : nil
232
232
  end
233
233
 
234
- def self.parse(version, loose = false)
234
+ def self.parse(version, loose: false)
235
235
  return version if version.is_a?(Version)
236
236
 
237
237
  return nil unless version.is_a?(String)
@@ -243,23 +243,18 @@ module SemanticRange
243
243
  rxp = loose ? LOOSE : FULL
244
244
  return nil if !rxp.match(stripped_version)
245
245
 
246
- Version.new(stripped_version, loose)
246
+ Version.new(stripped_version, loose: loose)
247
247
  end
248
248
 
249
- def self.increment!(version, release, loose, identifier)
250
- if loose.is_a? String
251
- identifier = loose
252
- loose = false
253
- end
254
-
255
- Version.new(version, loose).increment!(release, identifier).version
249
+ def self.increment!(version, release, identifier, loose: false)
250
+ Version.new(version, loose: loose).increment!(release, identifier).version
256
251
  rescue InvalidIncrement, InvalidVersion
257
252
  nil
258
253
  end
259
254
 
260
255
  def self.diff(a, b)
261
- a = Version.new(a, false) unless a.kind_of?(Version)
262
- b = Version.new(b, false) unless b.kind_of?(Version)
256
+ a = Version.new(a, loose: false) unless a.kind_of?(Version)
257
+ b = Version.new(b, loose: false) unless b.kind_of?(Version)
263
258
  pre_diff = a.prerelease.to_s != b.prerelease.to_s
264
259
  pre = pre_diff ? 'pre' : ''
265
260
  return "#{pre}major" if a.major != b.major
@@ -268,8 +263,8 @@ module SemanticRange
268
263
  return "prerelease" if pre_diff
269
264
  end
270
265
 
271
- def self.to_comparators(range, loose = false, platform = nil)
272
- Range.new(range, loose, platform).set.map do |comp|
266
+ def self.to_comparators(range, loose: false, platform: nil)
267
+ Range.new(range, loose: loose, platform: platform).set.map do |comp|
273
268
  comp.map(&:to_s)
274
269
  end
275
270
  end
@@ -17,7 +17,7 @@ module SemanticRange
17
17
  def test(version)
18
18
  return true if @semver == ANY
19
19
  version = Version.new(version, @loose) if version.is_a?(String)
20
- SemanticRange.cmp(version, @operator, @semver, @loose)
20
+ SemanticRange.cmp(version, @operator, @semver, loose: @loose)
21
21
  end
22
22
 
23
23
  def parse(comp)
@@ -27,26 +27,26 @@ module SemanticRange
27
27
  @operator = m[1]
28
28
  @operator = '' if @operator == '='
29
29
 
30
- @semver = !m[2] ? ANY : Version.new(m[2], @loose)
30
+ @semver = !m[2] ? ANY : Version.new(m[2], loose: @loose)
31
31
  end
32
32
 
33
- def intersects?(comp, loose = false, platform = nil)
33
+ def intersects?(comp, loose: false, platform: nil)
34
34
  comp = Comparator.new(comp, loose)
35
35
 
36
36
  if @operator == ''
37
- range_b = Range.new(comp.value, loose, platform)
38
- SemanticRange.satisfies?(@value, range_b, loose, platform)
37
+ range_b = Range.new(comp.value, loose: loose, platform: platform)
38
+ SemanticRange.satisfies?(@value, range_b, loose: loose, platform: platform)
39
39
  elsif comp.operator == ''
40
- range_a = Range.new(@value, loose, platform)
41
- SemanticRange.satisfies?(comp.semver, range_a, loose, platform)
40
+ range_a = Range.new(@value, loose: loose, platform: platform)
41
+ SemanticRange.satisfies?(comp.semver, range_a, loose: loose, platform: platform)
42
42
  else
43
43
  same_direction_increasing = (@operator == '>=' || @operator == '>') && (comp.operator == '>=' || comp.operator == '>')
44
44
  same_direction_decreasing = (@operator == '<=' || @operator == '<') && (comp.operator == '<=' || comp.operator == '<')
45
45
  same_version = @semver.raw == comp.semver.raw
46
46
  different_directions_inclusive = (@operator == '>=' || @operator == '<=') && (comp.operator == '>=' || comp.operator == '<=')
47
- opposite_directions_lte = SemanticRange.cmp(@semver, '<', comp.semver, loose) &&
47
+ opposite_directions_lte = SemanticRange.cmp(@semver, '<', comp.semver, loose: loose) &&
48
48
  ((@operator == '>=' || @operator == '>') && (comp.operator == '<=' || comp.operator == '<'))
49
- opposite_directions_gte = SemanticRange.cmp(@semver, '>', comp.semver, loose) &&
49
+ opposite_directions_gte = SemanticRange.cmp(@semver, '>', comp.semver, loose: loose) &&
50
50
  ((@operator == '<=' || @operator == '<') && (comp.operator == '>=' || comp.operator == '>'))
51
51
 
52
52
  same_direction_increasing || same_direction_decreasing || (same_version && different_directions_inclusive) ||
@@ -54,12 +54,12 @@ module SemanticRange
54
54
  end
55
55
  end
56
56
 
57
- def satisfies_range?(range, loose = false, platform = nil)
58
- range = Range.new(range, loose, platform)
57
+ def satisfies_range?(range, loose: false, platform: nil)
58
+ range = Range.new(range, loose: loose, platform: platform)
59
59
 
60
60
  range.set.any? do |comparators|
61
61
  comparators.all? do |comparator|
62
- intersects?(comparator, loose, platform)
62
+ intersects?(comparator, loose: loose, platform: platform)
63
63
  end
64
64
  end
65
65
  end
@@ -2,7 +2,7 @@ module SemanticRange
2
2
  class Range
3
3
  attr_reader :loose, :raw, :range, :set, :platform
4
4
 
5
- def initialize(range, loose = false, platform = nil)
5
+ def initialize(range, loose: false, platform: nil)
6
6
  range = range.raw if range.is_a?(Range)
7
7
  @platform = platform
8
8
  @raw = range
@@ -31,7 +31,7 @@ module SemanticRange
31
31
 
32
32
  def test(version)
33
33
  return false if !version
34
- version = Version.new(version, @loose) if version.is_a?(String)
34
+ version = Version.new(version, loose: @loose) if version.is_a?(String)
35
35
  @set.any?{|s| test_set(s, version) }
36
36
  end
37
37
 
@@ -283,12 +283,12 @@ module SemanticRange
283
283
  "#{from} #{to}".strip
284
284
  end
285
285
 
286
- def intersects(range, loose = false, platform = nil)
287
- range = Range.new(range, loose, platform)
286
+ def intersects(range, loose: false, platform: nil)
287
+ range = Range.new(range, loose: loose, platform: platform)
288
288
 
289
289
  @set.any? do |comparators|
290
290
  comparators.all? do |comparator|
291
- comparator.satisfies_range(range, loose, platform)
291
+ comparator.satisfies_range(range, loose: loose, platform: platform)
292
292
  end
293
293
  end
294
294
  end
@@ -1,10 +1,10 @@
1
1
  module SemanticRange
2
- VERSION = "2.3.1"
2
+ VERSION = "3.0.0"
3
3
 
4
4
  class Version
5
5
  attr_reader :major, :minor, :patch, :prerelease
6
6
 
7
- def initialize(version, loose = false)
7
+ def initialize(version, loose: false)
8
8
  @raw = version
9
9
  @loose = loose
10
10
 
@@ -45,13 +45,13 @@ module SemanticRange
45
45
  end
46
46
 
47
47
  def compare(other)
48
- other = Version.new(other, @loose) unless other.is_a?(Version)
48
+ other = Version.new(other, loose: @loose) unless other.is_a?(Version)
49
49
  res = truthy(compare_main(other)) || truthy(compare_pre(other))
50
50
  res.is_a?(FalseClass) ? 0 : res
51
51
  end
52
52
 
53
53
  def compare_main(other)
54
- other = Version.new(other, @loose) unless other.is_a?(Version)
54
+ other = Version.new(other, loose: @loose) unless other.is_a?(Version)
55
55
  truthy(self.class.compare_identifiers(@major, other.major)) ||
56
56
  truthy(self.class.compare_identifiers(@minor, other.minor)) ||
57
57
  truthy(self.class.compare_identifiers(@patch, other.patch))
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_range
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-02 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
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.11'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.11'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '12.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '12.0'
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: rspec
43
15
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +24,7 @@ dependencies:
52
24
  - - "~>"
53
25
  - !ruby/object:Gem::Version
54
26
  version: '3.4'
55
- description:
27
+ description:
56
28
  email:
57
29
  - andrewnez@gmail.com
58
30
  executables: []
@@ -70,7 +42,7 @@ homepage: https://libraries.io/github/librariesio/semantic_range
70
42
  licenses:
71
43
  - MIT
72
44
  metadata: {}
73
- post_install_message:
45
+ post_install_message:
74
46
  rdoc_options: []
75
47
  require_paths:
76
48
  - lib
@@ -85,8 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
57
  - !ruby/object:Gem::Version
86
58
  version: '0'
87
59
  requirements: []
88
- rubygems_version: 3.0.4
89
- signing_key:
60
+ rubygems_version: 3.1.2
61
+ signing_key:
90
62
  specification_version: 4
91
63
  summary: node-semver rewritten in ruby, for comparison and inclusion of semantic versions
92
64
  and ranges