iri 0.11.8 → 0.11.9
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/Gemfile +4 -3
- data/Gemfile.lock +53 -47
- data/Rakefile +1 -1
- data/iri.gemspec +2 -2
- data/lib/iri.rb +52 -38
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: abe9911f8ce128a5e8f13a1b11332ea34f4e9015aca21a08e24748b0f60473f3
|
|
4
|
+
data.tar.gz: e0c8da124aecdbf300606756ed40fcbcca32e30298e75f5250da75ff63696059
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8015b75d87a8ef2acd8fce08fa1e7c5282a9f8346d484e24b1f26b751577d5fc136ec1d4e71b0083023cedaacd5f5d4fdd745cd53e45e71ff195e977ed7c37db
|
|
7
|
+
data.tar.gz: 221e28c8445762a722d7741d522cdfd2c001cb47bf9676da06b3809938a708e01a2fa30c1defe84b8715c91fe91121a9f172580f2499bcd5e52699c9178d80f2
|
data/Gemfile
CHANGED
|
@@ -9,11 +9,12 @@ gemspec
|
|
|
9
9
|
gem 'minitest', '~>6.0', require: false
|
|
10
10
|
gem 'minitest-reporters', '~>1.7', require: false
|
|
11
11
|
gem 'rake', '~>13.2', require: false
|
|
12
|
-
gem 'rdoc', '
|
|
12
|
+
gem 'rdoc', '8.1.0', require: false
|
|
13
13
|
gem 'rubocop', '~>1.74', require: false
|
|
14
|
+
gem 'rubocop-elegant', '~>0.5', require: false
|
|
14
15
|
gem 'rubocop-minitest', '~>0.38', require: false
|
|
15
16
|
gem 'rubocop-performance', '~>1.25', require: false
|
|
16
17
|
gem 'rubocop-rake', '~>0.7', require: false
|
|
17
|
-
gem 'simplecov', '~>0
|
|
18
|
-
gem 'simplecov-cobertura', '~>
|
|
18
|
+
gem 'simplecov', '~>1.0', require: false
|
|
19
|
+
gem 'simplecov-cobertura', '~>4.0', require: false
|
|
19
20
|
gem 'yard', '~>0.9', require: false
|
data/Gemfile.lock
CHANGED
|
@@ -6,80 +6,85 @@ PATH
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
ansi (1.
|
|
9
|
+
ansi (1.6.1)
|
|
10
|
+
logger
|
|
10
11
|
ast (2.4.3)
|
|
11
12
|
builder (3.3.0)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
language_server-protocol (3.17.0.5)
|
|
13
|
+
drb (2.2.3)
|
|
14
|
+
erb (6.0.7)
|
|
15
|
+
json (3.2.0)
|
|
16
|
+
language_server-protocol (3.17.0.6)
|
|
17
17
|
lint_roller (1.1.0)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
logger (1.7.0)
|
|
19
|
+
minitest (6.1.0)
|
|
20
|
+
drb (~> 2.0)
|
|
21
|
+
prism (>= 1.5, < 3)
|
|
22
|
+
minitest-reporters (1.8.0)
|
|
21
23
|
ansi
|
|
22
24
|
builder
|
|
23
|
-
minitest (>= 5.0)
|
|
25
|
+
minitest (>= 5.0, < 7)
|
|
24
26
|
ruby-progressbar
|
|
25
|
-
parallel (
|
|
26
|
-
parser (3.3.
|
|
27
|
+
parallel (2.3.0)
|
|
28
|
+
parser (3.3.14.0)
|
|
27
29
|
ast (~> 2.4.1)
|
|
28
30
|
racc
|
|
29
|
-
prism (1.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
stringio
|
|
31
|
+
prism (2.1.0)
|
|
32
|
+
prism (2.1.0-arm64-darwin)
|
|
33
|
+
prism (2.1.0-x64-mingw-ucrt)
|
|
33
34
|
racc (1.8.1)
|
|
34
35
|
rainbow (3.1.1)
|
|
35
|
-
rake (13.
|
|
36
|
-
|
|
36
|
+
rake (13.4.2)
|
|
37
|
+
rbs (4.2.0)
|
|
38
|
+
logger
|
|
39
|
+
prism (>= 1.6.0)
|
|
40
|
+
tsort
|
|
41
|
+
rdoc (8.1.0)
|
|
37
42
|
erb
|
|
38
|
-
|
|
43
|
+
prism (>= 1.6.0)
|
|
44
|
+
rbs (>= 4.0.0)
|
|
39
45
|
tsort
|
|
40
|
-
regexp_parser (2.
|
|
46
|
+
regexp_parser (2.13.4)
|
|
41
47
|
rexml (3.4.4)
|
|
42
|
-
rubocop (1.
|
|
43
|
-
json (
|
|
48
|
+
rubocop (1.93.0)
|
|
49
|
+
json (>= 2.3)
|
|
44
50
|
language_server-protocol (~> 3.17.0.2)
|
|
45
51
|
lint_roller (~> 1.1.0)
|
|
46
|
-
parallel (
|
|
52
|
+
parallel (>= 1.10)
|
|
47
53
|
parser (>= 3.3.0.2)
|
|
48
54
|
rainbow (>= 2.2.2, < 4.0)
|
|
49
|
-
regexp_parser (>= 2.
|
|
50
|
-
rubocop-ast (>= 1.
|
|
55
|
+
regexp_parser (>= 2.11.3, < 3.0)
|
|
56
|
+
rubocop-ast (>= 1.54.0, < 2.0)
|
|
51
57
|
ruby-progressbar (~> 1.7)
|
|
52
58
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
53
|
-
rubocop-ast (1.
|
|
59
|
+
rubocop-ast (1.54.0)
|
|
60
|
+
ast (~> 2.4)
|
|
54
61
|
parser (>= 3.3.7.2)
|
|
55
|
-
prism (
|
|
56
|
-
|
|
62
|
+
prism (>= 1.7)
|
|
63
|
+
racc
|
|
64
|
+
rubocop-elegant (0.8.0)
|
|
65
|
+
lint_roller (~> 1.1)
|
|
66
|
+
rubocop (~> 1.75)
|
|
67
|
+
rubocop-minitest (0.41.0)
|
|
57
68
|
lint_roller (~> 1.1)
|
|
58
|
-
rubocop (>= 1.
|
|
69
|
+
rubocop (>= 1.89.0, < 2.0)
|
|
59
70
|
rubocop-ast (>= 1.38.0, < 2.0)
|
|
60
|
-
rubocop-performance (1.
|
|
71
|
+
rubocop-performance (1.27.0)
|
|
61
72
|
lint_roller (~> 1.1)
|
|
62
|
-
rubocop (>= 1.
|
|
73
|
+
rubocop (>= 1.89.0, < 2.0)
|
|
63
74
|
rubocop-ast (>= 1.47.1, < 2.0)
|
|
64
75
|
rubocop-rake (0.7.1)
|
|
65
76
|
lint_roller (~> 1.1)
|
|
66
77
|
rubocop (>= 1.72.1)
|
|
67
78
|
ruby-progressbar (1.13.0)
|
|
68
|
-
simplecov (
|
|
69
|
-
|
|
70
|
-
simplecov-html (~> 0.11)
|
|
71
|
-
simplecov_json_formatter (~> 0.1)
|
|
72
|
-
simplecov-cobertura (3.1.0)
|
|
79
|
+
simplecov (1.3.2)
|
|
80
|
+
simplecov-cobertura (4.0.0)
|
|
73
81
|
rexml
|
|
74
|
-
simplecov (~> 0
|
|
75
|
-
simplecov-html (0.13.2)
|
|
76
|
-
simplecov_json_formatter (0.1.4)
|
|
77
|
-
stringio (3.2.0)
|
|
82
|
+
simplecov (~> 1.0)
|
|
78
83
|
tsort (0.2.0)
|
|
79
|
-
unicode-display_width (3.
|
|
80
|
-
unicode-emoji (~> 4.
|
|
81
|
-
unicode-emoji (4.
|
|
82
|
-
yard (0.9.
|
|
84
|
+
unicode-display_width (3.3.0)
|
|
85
|
+
unicode-emoji (~> 4.3)
|
|
86
|
+
unicode-emoji (4.3.0)
|
|
87
|
+
yard (0.9.46)
|
|
83
88
|
|
|
84
89
|
PLATFORMS
|
|
85
90
|
arm64-darwin-23
|
|
@@ -92,13 +97,14 @@ DEPENDENCIES
|
|
|
92
97
|
minitest (~> 6.0)
|
|
93
98
|
minitest-reporters (~> 1.7)
|
|
94
99
|
rake (~> 13.2)
|
|
95
|
-
rdoc (=
|
|
100
|
+
rdoc (= 8.1.0)
|
|
96
101
|
rubocop (~> 1.74)
|
|
102
|
+
rubocop-elegant (~> 0.5)
|
|
97
103
|
rubocop-minitest (~> 0.38)
|
|
98
104
|
rubocop-performance (~> 1.25)
|
|
99
105
|
rubocop-rake (~> 0.7)
|
|
100
|
-
simplecov (~> 0
|
|
101
|
-
simplecov-cobertura (~>
|
|
106
|
+
simplecov (~> 1.0)
|
|
107
|
+
simplecov-cobertura (~> 4.0)
|
|
102
108
|
yard (~> 0.9)
|
|
103
109
|
|
|
104
110
|
BUNDLED WITH
|
data/Rakefile
CHANGED
data/iri.gemspec
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
require 'English'
|
|
7
7
|
|
|
8
8
|
Gem::Specification.new do |s|
|
|
9
|
-
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to?
|
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to?(:required_rubygems_version=)
|
|
10
10
|
s.required_ruby_version = '>=2.2'
|
|
11
11
|
s.name = 'iri'
|
|
12
|
-
s.version = '0.11.
|
|
12
|
+
s.version = '0.11.9'
|
|
13
13
|
s.license = 'MIT'
|
|
14
14
|
s.summary = 'Simple Immutable Ruby URI Builder'
|
|
15
15
|
s.description =
|
data/lib/iri.rb
CHANGED
|
@@ -60,7 +60,7 @@ class Iri
|
|
|
60
60
|
# @param [Boolean] safe When true, prevents InvalidURI exceptions
|
|
61
61
|
# @raise [InvalidURI] If the URI is malformed and safe is false
|
|
62
62
|
def initialize(uri = '', local: false, safe: true)
|
|
63
|
-
raise
|
|
63
|
+
raise(ArgumentError, "The uri can't be nil") if uri.nil?
|
|
64
64
|
@uri = uri.to_s
|
|
65
65
|
@local = local
|
|
66
66
|
@safe = safe
|
|
@@ -138,9 +138,9 @@ class Iri
|
|
|
138
138
|
# @see #del
|
|
139
139
|
# @see #over
|
|
140
140
|
def add(hash)
|
|
141
|
-
raise
|
|
142
|
-
raise
|
|
143
|
-
|
|
141
|
+
raise(ArgumentError, "The hash can't be nil") if hash.nil?
|
|
142
|
+
raise(InvalidArguments) unless hash.is_a?(Hash)
|
|
143
|
+
requery do |params|
|
|
144
144
|
hash.each do |k, v|
|
|
145
145
|
next if v.nil?
|
|
146
146
|
params[k.to_s] = [] unless params[k.to_s]
|
|
@@ -167,7 +167,7 @@ class Iri
|
|
|
167
167
|
# @see #add
|
|
168
168
|
# @see #over
|
|
169
169
|
def del(*keys)
|
|
170
|
-
|
|
170
|
+
requery do |params|
|
|
171
171
|
keys.each do |k|
|
|
172
172
|
params.delete(k.to_s)
|
|
173
173
|
end
|
|
@@ -179,7 +179,7 @@ class Iri
|
|
|
179
179
|
#
|
|
180
180
|
# Unlike #add, this method replaces any existing parameters with the same name
|
|
181
181
|
# rather than adding additional instances. If a parameter doesn't exist,
|
|
182
|
-
# it will be added.
|
|
182
|
+
# it will be added. If the value is nil, the parameter is removed.
|
|
183
183
|
#
|
|
184
184
|
# @example Replacing a query parameter
|
|
185
185
|
# Iri.new('https://google.com?q=test').over(q: 'hey you!')
|
|
@@ -189,18 +189,26 @@ class Iri
|
|
|
189
189
|
# Iri.new('https://google.com?q=test&limit=5').over(q: 'books', limit: 10)
|
|
190
190
|
# # => "https://google.com?q=books&limit=10"
|
|
191
191
|
#
|
|
192
|
+
# @example Removing a query parameter with a nil value
|
|
193
|
+
# Iri.new('https://google.com?q=test&limit=5').over(q: nil)
|
|
194
|
+
# # => "https://google.com?limit=5"
|
|
195
|
+
#
|
|
192
196
|
# @param [Hash] hash Hash of parameter names/values to replace in the query part
|
|
193
197
|
# @return [Iri] A new Iri instance
|
|
194
198
|
# @raise [InvalidArguments] If the argument is not a Hash
|
|
195
199
|
# @see #add
|
|
196
200
|
# @see #del
|
|
197
201
|
def over(hash)
|
|
198
|
-
raise
|
|
199
|
-
raise
|
|
200
|
-
|
|
202
|
+
raise(ArgumentError, "The hash can't be nil") if hash.nil?
|
|
203
|
+
raise(InvalidArguments) unless hash.is_a?(Hash)
|
|
204
|
+
requery do |params|
|
|
201
205
|
hash.each do |k, v|
|
|
202
|
-
|
|
203
|
-
|
|
206
|
+
if v.nil?
|
|
207
|
+
params.delete(k.to_s)
|
|
208
|
+
else
|
|
209
|
+
params[k.to_s] = [] unless params[k.to_s]
|
|
210
|
+
params[k.to_s] = [v]
|
|
211
|
+
end
|
|
204
212
|
end
|
|
205
213
|
end
|
|
206
214
|
end
|
|
@@ -216,9 +224,9 @@ class Iri
|
|
|
216
224
|
# @see #host
|
|
217
225
|
# @see #port
|
|
218
226
|
def scheme(val)
|
|
219
|
-
raise
|
|
227
|
+
raise(ArgumentError, "The scheme can't be nil") if val.nil?
|
|
220
228
|
val = val.to_s
|
|
221
|
-
raise
|
|
229
|
+
raise(ArgumentError, "The scheme can't be empty") if val.empty?
|
|
222
230
|
modify(local: false) do |c|
|
|
223
231
|
c.scheme = val
|
|
224
232
|
end
|
|
@@ -235,9 +243,9 @@ class Iri
|
|
|
235
243
|
# @see #scheme
|
|
236
244
|
# @see #port
|
|
237
245
|
def host(val)
|
|
238
|
-
raise
|
|
246
|
+
raise(ArgumentError, "The host can't be nil") if val.nil?
|
|
239
247
|
val = val.to_s
|
|
240
|
-
raise
|
|
248
|
+
raise(ArgumentError, "The host can't be empty") if val.empty?
|
|
241
249
|
modify(local: false) do |c|
|
|
242
250
|
c.scheme ||= 'http'
|
|
243
251
|
c.host = val
|
|
@@ -255,11 +263,11 @@ class Iri
|
|
|
255
263
|
# @see #scheme
|
|
256
264
|
# @see #host
|
|
257
265
|
def port(val)
|
|
258
|
-
raise
|
|
259
|
-
val = val
|
|
260
|
-
raise
|
|
261
|
-
raise
|
|
262
|
-
raise
|
|
266
|
+
raise(ArgumentError, "The port can't be nil") if val.nil?
|
|
267
|
+
val = Integer(val)
|
|
268
|
+
raise(ArgumentError, "The port can't be negative") if val.negative?
|
|
269
|
+
raise(ArgumentError, "The port can't be zero") if val.zero?
|
|
270
|
+
raise(ArgumentError, "The port can't be larger than 65535") if val > 65_535
|
|
263
271
|
modify(local: false) do |c|
|
|
264
272
|
c.scheme ||= 'http'
|
|
265
273
|
c.port = val
|
|
@@ -277,9 +285,9 @@ class Iri
|
|
|
277
285
|
# @see #query
|
|
278
286
|
# @see #fragment
|
|
279
287
|
def path(val)
|
|
280
|
-
raise
|
|
288
|
+
raise(ArgumentError, "The path can't be nil") if val.nil?
|
|
281
289
|
val = val.to_s
|
|
282
|
-
raise
|
|
290
|
+
raise(ArgumentError, "The path can't be empty") if val.empty?
|
|
283
291
|
modify do |c|
|
|
284
292
|
c.path = val
|
|
285
293
|
end
|
|
@@ -296,7 +304,7 @@ class Iri
|
|
|
296
304
|
# @see #path
|
|
297
305
|
# @see #query
|
|
298
306
|
def fragment(val)
|
|
299
|
-
raise
|
|
307
|
+
raise(ArgumentError, "The fragment can't be nil") if val.nil?
|
|
300
308
|
val = val.to_s
|
|
301
309
|
modify do |c|
|
|
302
310
|
c.fragment = val.empty? ? nil : val
|
|
@@ -318,7 +326,7 @@ class Iri
|
|
|
318
326
|
# @see #del
|
|
319
327
|
# @see #over
|
|
320
328
|
def query(val)
|
|
321
|
-
raise
|
|
329
|
+
raise(ArgumentError, "The query can't be nil") if val.nil?
|
|
322
330
|
val = val.to_s
|
|
323
331
|
modify do |c|
|
|
324
332
|
c.query = val.empty? ? nil : val
|
|
@@ -344,9 +352,9 @@ class Iri
|
|
|
344
352
|
# @see #query
|
|
345
353
|
# @see #fragment
|
|
346
354
|
def cut(path = '/')
|
|
347
|
-
raise
|
|
355
|
+
raise(ArgumentError, "The path can't be nil") if path.nil?
|
|
348
356
|
path = path.to_s
|
|
349
|
-
raise
|
|
357
|
+
raise(ArgumentError, "The path can't be empty") if path.empty?
|
|
350
358
|
modify do |c|
|
|
351
359
|
s = Iri.new(path).to_uri
|
|
352
360
|
c.query = s.query
|
|
@@ -366,7 +374,7 @@ class Iri
|
|
|
366
374
|
#
|
|
367
375
|
# @example Appending to a path with a trailing slash
|
|
368
376
|
# Iri.new('https://example.com/a/').append('hello')
|
|
369
|
-
# # => "https://example.com/a/hello
|
|
377
|
+
# # => "https://example.com/a/hello"
|
|
370
378
|
#
|
|
371
379
|
# @example Appending a segment that needs URL encoding
|
|
372
380
|
# Iri.new('https://example.com/docs').append('section 1')
|
|
@@ -376,12 +384,11 @@ class Iri
|
|
|
376
384
|
# @return [Iri] A new Iri instance
|
|
377
385
|
# @see #path
|
|
378
386
|
def append(part)
|
|
379
|
-
raise
|
|
387
|
+
raise(ArgumentError, "The part can't be nil") if part.nil?
|
|
380
388
|
part = part.to_s
|
|
381
|
-
raise
|
|
389
|
+
raise(ArgumentError, "The part can't be empty") if part.empty?
|
|
382
390
|
modify do |c|
|
|
383
|
-
|
|
384
|
-
c.path = c.path + tail
|
|
391
|
+
c.path = c.path + ((c.path.end_with?('/') ? '' : '/') + URI.encode_www_form_component(part.to_s))
|
|
385
392
|
end
|
|
386
393
|
end
|
|
387
394
|
|
|
@@ -398,7 +405,7 @@ class Iri
|
|
|
398
405
|
def the_uri
|
|
399
406
|
@the_uri ||= URI(@uri)
|
|
400
407
|
rescue URI::InvalidURIError => e
|
|
401
|
-
raise
|
|
408
|
+
raise(InvalidURI, e.message) unless @safe
|
|
402
409
|
@the_uri = URI('/')
|
|
403
410
|
end
|
|
404
411
|
|
|
@@ -411,8 +418,11 @@ class Iri
|
|
|
411
418
|
# @return [Iri] A new Iri instance with the modified URI
|
|
412
419
|
def modify(local: @local, safe: @safe)
|
|
413
420
|
c = the_uri.clone
|
|
414
|
-
yield
|
|
421
|
+
yield(c)
|
|
415
422
|
Iri.new(c, local: local, safe: safe)
|
|
423
|
+
rescue URI::Error
|
|
424
|
+
raise unless safe
|
|
425
|
+
Iri.new(@uri, local: local, safe: safe)
|
|
416
426
|
end
|
|
417
427
|
|
|
418
428
|
# Creates a new Iri object after modifying the query parameters.
|
|
@@ -423,13 +433,17 @@ class Iri
|
|
|
423
433
|
#
|
|
424
434
|
# @yield [Hash] The parsed query parameters for modification
|
|
425
435
|
# @return [Iri] A new Iri instance with the modified query string
|
|
426
|
-
def
|
|
436
|
+
def requery
|
|
427
437
|
modify do |c|
|
|
428
|
-
params =
|
|
429
|
-
(
|
|
430
|
-
|
|
438
|
+
params =
|
|
439
|
+
(the_uri.query || '').split('&').each_with_object({}) do |pair, h|
|
|
440
|
+
next if pair.empty?
|
|
441
|
+
k, v = URI.decode_www_form(pair).first
|
|
442
|
+
(h[k] ||= []) << (pair.include?('=') ? v : nil)
|
|
443
|
+
end
|
|
431
444
|
yield(params)
|
|
432
|
-
|
|
445
|
+
form = URI.encode_www_form(params.flat_map { |k, vs| vs.map { |v| [k, v] } })
|
|
446
|
+
c.query = form.empty? ? nil : form
|
|
433
447
|
end
|
|
434
448
|
end
|
|
435
449
|
end
|