iri 0.1.0 → 0.2.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/README.md +1 -0
- data/iri.gemspec +1 -1
- data/lib/iri.rb +27 -0
- data/test/test_iri.rb +21 -0
- 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: 12449f264a53cb485147418a1dac3bf592d6739bc9907a9150c742d67f0cea67
|
4
|
+
data.tar.gz: 47b3d56c0cf5f9b613fdb4902c98bd385cce90450271e9256ec5cab8ce2cfdfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4aa33c7601a7f6ea0f06e14a091d644efd48ee821198fedecf78bedbb34adba049d203cd2466f7f2562ed3344ea8d6a7e5462732c56c36872ac343611a25f29
|
7
|
+
data.tar.gz: 372918b261d96aa75a6c8f813ee315e7dc9a1a32e31343b5bbd2d54b325726771f5650bd86a7a87d76204300a19a20b31523fdc79a557b9bdb319d2a9cab2ce4
|
data/README.md
CHANGED
data/iri.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.rubygems_version = '2.5'
|
32
32
|
s.required_ruby_version = '>=2.5'
|
33
33
|
s.name = 'iri'
|
34
|
-
s.version = '0.
|
34
|
+
s.version = '0.2.0'
|
35
35
|
s.license = 'MIT'
|
36
36
|
s.summary = 'Simple Immutable Ruby URI Builder'
|
37
37
|
s.description = 'Simple Immutable Ruby URI Builder'
|
data/lib/iri.rb
CHANGED
@@ -75,6 +75,7 @@ class Iri
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
# Replace the query argument(s).
|
78
79
|
def over(hash)
|
79
80
|
modify_query do |params|
|
80
81
|
hash.each do |k, v|
|
@@ -84,24 +85,50 @@ class Iri
|
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
88
|
+
# Replace the scheme.
|
87
89
|
def scheme(val)
|
88
90
|
modify do |c|
|
89
91
|
c.scheme = val
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
95
|
+
# Replace the host.
|
93
96
|
def host(val)
|
94
97
|
modify do |c|
|
95
98
|
c.host = val
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
102
|
+
# Replace the port.
|
99
103
|
def port(val)
|
100
104
|
modify do |c|
|
101
105
|
c.port = val
|
102
106
|
end
|
103
107
|
end
|
104
108
|
|
109
|
+
# Replace the path part of the URI.
|
110
|
+
def path(val)
|
111
|
+
modify do |c|
|
112
|
+
c.path = val
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Replace the query part of the URI.
|
117
|
+
def query(val)
|
118
|
+
modify do |c|
|
119
|
+
c.query = val
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Remove the entire path+query+fragment part.
|
124
|
+
def cut(path = '/')
|
125
|
+
modify do |c|
|
126
|
+
c.query = nil
|
127
|
+
c.path = path
|
128
|
+
c.fragment = nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
105
132
|
private
|
106
133
|
|
107
134
|
def modify
|
data/test/test_iri.rb
CHANGED
@@ -64,6 +64,27 @@ class IriTest < Minitest::Test
|
|
64
64
|
)
|
65
65
|
end
|
66
66
|
|
67
|
+
def test_sets_path
|
68
|
+
assert_equal(
|
69
|
+
'http://localhost/hey/you?i=8#test',
|
70
|
+
Iri.new('http://localhost/hey?i=8#test').path('/hey/you').to_s
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_sets_query
|
75
|
+
assert_equal(
|
76
|
+
'http://localhost/hey?t=1#test',
|
77
|
+
Iri.new('http://localhost/hey?i=8#test').query('t=1').to_s
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_removes_query_and_path
|
82
|
+
assert_equal(
|
83
|
+
'http://localhost/',
|
84
|
+
Iri.new('http://localhost/hey?i=8#test').cut.to_s
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
67
88
|
def test_adds_query_param
|
68
89
|
assert_equal(
|
69
90
|
'http://google/?a=1&a=3&b=2',
|