iri 0.9.0 → 0.10.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/iri.gemspec +1 -1
- data/lib/iri.rb +17 -11
- data/test/test_iri.rb +5 -1
- 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: c9981ebf1f6a24c408671ca60df156211a1866a23c0ba2a5e8a7424dfb8461b4
|
4
|
+
data.tar.gz: f0bcbb8b78b70e14b1e6b42c7b141174aca57d00d0b1e33e101061bb10f12ee0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cbeb1064fabf1906d158a48219f418a11ac0d11ed40b436988006710002c8b0ce3cb66381905e23e28c4b4479ebc4a03b324f7a3a4dc7692b5b11bee4d44361
|
7
|
+
data.tar.gz: fa47c762b50c2046f0d7b3beb3dce405362cd2079d04d554f764b88b985421510242a7fe281093eb7927b01a6c92d15cd41d6cccdad0be60d1f4513669876bf0
|
data/iri.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
28
28
|
s.required_ruby_version = '>=2.2'
|
29
29
|
s.name = 'iri'
|
30
|
-
s.version = '0.
|
30
|
+
s.version = '0.10.0'
|
31
31
|
s.license = 'MIT'
|
32
32
|
s.summary = 'Simple Immutable Ruby URI Builder'
|
33
33
|
s.description = "Class Iri helps you build a URI and then modify its \
|
data/lib/iri.rb
CHANGED
@@ -60,9 +60,11 @@ class Iri
|
|
60
60
|
# you can turn this mode off, by specifying safe as FALSE.
|
61
61
|
#
|
62
62
|
# @param [String] uri URI
|
63
|
-
# @param [Boolean]
|
64
|
-
|
63
|
+
# @param [Boolean] local Is it local (no host, port, and scheme)?
|
64
|
+
# @param [Boolean] safe Should it safe?
|
65
|
+
def initialize(uri = '', local: false, safe: true)
|
65
66
|
@uri = uri
|
67
|
+
@local = local
|
66
68
|
@safe = safe
|
67
69
|
end
|
68
70
|
|
@@ -70,7 +72,16 @@ class Iri
|
|
70
72
|
#
|
71
73
|
# @return [String] New URI
|
72
74
|
def to_s
|
73
|
-
|
75
|
+
u = the_uri
|
76
|
+
if @local
|
77
|
+
[
|
78
|
+
u.path,
|
79
|
+
u.query ? "?#{u.query}" : '',
|
80
|
+
u.fragment ? "##{u.fragment}" : ''
|
81
|
+
].join
|
82
|
+
else
|
83
|
+
u.to_s
|
84
|
+
end
|
74
85
|
end
|
75
86
|
|
76
87
|
# Inspect it, like a string can be inspected.
|
@@ -91,14 +102,9 @@ class Iri
|
|
91
102
|
# only the local address, for example, converting "https://google.com/foo"
|
92
103
|
# into "/foo".
|
93
104
|
#
|
94
|
-
# @return [
|
105
|
+
# @return [Iri] Iri with no host/port/scheme
|
95
106
|
def to_local
|
96
|
-
|
97
|
-
[
|
98
|
-
u.path,
|
99
|
-
u.query ? "?#{u.query}" : '',
|
100
|
-
u.fragment ? "##{u.fragment}" : ''
|
101
|
-
].join
|
107
|
+
Iri.new(@uri, local: true, safe: @safe)
|
102
108
|
end
|
103
109
|
|
104
110
|
# Add a few query arguments.
|
@@ -264,7 +270,7 @@ class Iri
|
|
264
270
|
def modify
|
265
271
|
c = the_uri.clone
|
266
272
|
yield c
|
267
|
-
Iri.new(c)
|
273
|
+
Iri.new(c, local: @local, safe: @safe)
|
268
274
|
end
|
269
275
|
|
270
276
|
def modify_query
|
data/test/test_iri.rb
CHANGED
@@ -58,7 +58,11 @@ class IriTest < Minitest::Test
|
|
58
58
|
'https://google.com/bar?x=900' => '/bar?x=900',
|
59
59
|
'https://google.com/what#yes' => '/what#yes',
|
60
60
|
'https://google.com/what?a=8&b=9#yes' => '/what?a=8&b=9#yes'
|
61
|
-
}.each { |a, b| assert_equal(b, Iri.new(a).to_local) }
|
61
|
+
}.each { |a, b| assert_equal(b, Iri.new(a).to_local.to_s) }
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_deals_with_local
|
65
|
+
assert_equal('/foo?x=1', Iri.new('https://google.com/foo').to_local.add(x: 1).to_s)
|
62
66
|
end
|
63
67
|
|
64
68
|
def test_broken_uri
|