iri 0.4.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -1
- data/.rultor.yml +7 -9
- data/.travis.yml +1 -1
- data/Gemfile +2 -2
- data/LICENSE.txt +21 -0
- data/README.md +18 -6
- data/Rakefile +1 -1
- data/iri.gemspec +7 -6
- data/lib/iri.rb +38 -12
- data/logo.svg +19 -0
- data/test/test__helper.rb +30 -0
- data/test/test_iri.rb +30 -2
- metadata +27 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db8863ed27f231ba61cdff169239ea612436272a7150f036c9796fc2d90c0834
|
4
|
+
data.tar.gz: e67d192cf430e94f64c3aab87f4f064b6c4915e28c8c6d2dba82afda8aeaaeba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9be16a1579273c5796c63a121eb39d03061bfaae5e1fad217c76fe13699cb46f64d0c59c568227a6853cccec41f45b880a4c2ecc3f2e957516c38d5b6f05215
|
7
|
+
data.tar.gz: 1330a503f87585553fb4e507d7c81f3f0ef8c02583838b136110dfcc243cfa5da14a9b91bd8360a6e0df43f4bd719fdb63b4c1804a49cd5dcc798db161e7a813
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.rultor.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
assets:
|
2
|
-
rubygems.yml:
|
2
|
+
rubygems.yml: yegor256/home#assets/rubygems.yml
|
3
3
|
install: |-
|
4
4
|
export GEM_HOME=~/.ruby
|
5
5
|
export GEM_PATH=$GEM_HOME:$GEM_PATH
|
6
|
+
bundle install
|
6
7
|
release:
|
7
8
|
script: |-
|
8
|
-
bundle install
|
9
9
|
bundle exec rake
|
10
10
|
rm -rf *.gem
|
11
11
|
sed -i "s/0\.0\.0/${tag}/g" iri.gemspec
|
@@ -14,13 +14,11 @@ release:
|
|
14
14
|
gem build iri.gemspec
|
15
15
|
chmod 0600 ../rubygems.yml
|
16
16
|
gem push *.gem --config-file ../rubygems.yml
|
17
|
-
commanders:
|
18
|
-
- yegor256
|
19
|
-
architect:
|
20
|
-
- yegor256
|
21
17
|
merge:
|
22
|
-
commanders: []
|
23
18
|
script: |-
|
24
|
-
bundle install
|
25
19
|
bundle exec rake
|
26
|
-
deploy:
|
20
|
+
deploy:
|
21
|
+
script: |-
|
22
|
+
echo Nothing to deploy
|
23
|
+
exit 1
|
24
|
+
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2019 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2019-2021 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -21,5 +21,5 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
source 'https://rubygems.org'
|
24
|
-
ruby '~>2.
|
24
|
+
ruby '~>2.2'
|
25
25
|
gemspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019-2021 Yegor Bugayenko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included
|
13
|
+
in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
<img src="/logo.svg" width="64px" height="64px"/>
|
2
|
+
|
3
|
+
[![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)
|
2
4
|
[![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/iri)](http://www.rultor.com/p/yegor256/iri)
|
3
|
-
[![We recommend RubyMine](
|
5
|
+
[![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
|
4
6
|
|
5
7
|
[![Build Status](https://travis-ci.org/yegor256/iri.svg)](https://travis-ci.org/yegor256/iri)
|
6
8
|
[![Build status](https://ci.appveyor.com/api/projects/status/5hj65olpn2tds4al?svg=true)](https://ci.appveyor.com/project/yegor256/iri)
|
@@ -8,11 +10,13 @@
|
|
8
10
|
[![Maintainability](https://api.codeclimate.com/v1/badges/7018d2fe438103828685/maintainability)](https://codeclimate.com/github/yegor256/iri/maintainability)
|
9
11
|
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/iri/master/frames)
|
10
12
|
|
13
|
+
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/iri/blob/master/LICENSE.txt)
|
11
14
|
[![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/iri.svg)](https://codecov.io/github/yegor256/iri?branch=master)
|
12
15
|
[![Hits-of-Code](https://hitsofcode.com/github/yegor256/iri)](https://hitsofcode.com/view/github/yegor256/iri)
|
13
16
|
|
14
|
-
|
15
|
-
|
17
|
+
The class [`Iri`](https://www.rubydoc.info/github/yegor256/iri/master/Iri)
|
18
|
+
helps you build a URI and then modify its
|
19
|
+
parts via a simple [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface):
|
16
20
|
|
17
21
|
```ruby
|
18
22
|
require 'iri'
|
@@ -25,6 +29,10 @@ url = Iri.new('http://google.com/')
|
|
25
29
|
.scheme('https') # replace 'http' with 'https'
|
26
30
|
.host('localhost') # replace the host name
|
27
31
|
.port('443') # replace the port
|
32
|
+
.fragment('page-4') # replaces the fragment part of the URI, after the '#'
|
33
|
+
.query('a=1&b=2') # replaces the entire query part of the URI
|
34
|
+
.path('/new/path') # replace the path of the URI, leaving the query untouched
|
35
|
+
.cut('/q') # replace everything after the host and port
|
28
36
|
.to_s # convert it to a string
|
29
37
|
```
|
30
38
|
|
@@ -43,7 +51,9 @@ gem 'iri'
|
|
43
51
|
```
|
44
52
|
|
45
53
|
Pay attention, it is not a parser. The only functionality this gem provides
|
46
|
-
is _building_ URIs.
|
54
|
+
is _building_ URIs.
|
55
|
+
|
56
|
+
It is very convenient to use inside
|
47
57
|
[HAML](http://haml.info/tutorial.html), for example:
|
48
58
|
|
49
59
|
```haml
|
@@ -52,7 +62,9 @@ is _building_ URIs. It is very convenient to use inside
|
|
52
62
|
%a{href: iri.over(offset: offset - 10)} Previous Page
|
53
63
|
```
|
54
64
|
|
55
|
-
|
65
|
+
Of course, it's better to create the `iri` object only once per request
|
66
|
+
and re-use it where you need. It's _immutable_, so you won't have any
|
67
|
+
side-effects.
|
56
68
|
|
57
69
|
PS. See how I use it in this Sinatra web app: [yegor256/0rsk](https://github.com/yegor256/0rsk).
|
58
70
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2019 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2019-2021 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/iri.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2019-2021 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -29,23 +29,24 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.required_rubygems_version = Gem::Requirement.new('>= 0')
|
30
30
|
end
|
31
31
|
s.rubygems_version = '2.5'
|
32
|
-
s.required_ruby_version = '>=2.
|
32
|
+
s.required_ruby_version = '>=2.2'
|
33
33
|
s.name = 'iri'
|
34
|
-
s.version = '0.
|
34
|
+
s.version = '0.5.1'
|
35
35
|
s.license = 'MIT'
|
36
36
|
s.summary = 'Simple Immutable Ruby URI Builder'
|
37
37
|
s.description = 'Class Iri helps you build a URI and then modify its \
|
38
38
|
parts via a simple fluent interface.'
|
39
39
|
s.authors = ['Yegor Bugayenko']
|
40
40
|
s.email = 'yegor256@gmail.com'
|
41
|
-
s.homepage = '
|
41
|
+
s.homepage = 'https://github.com/yegor256/iri'
|
42
42
|
s.files = `git ls-files`.split($RS)
|
43
43
|
s.test_files = s.files.grep(%r{^(test)/})
|
44
44
|
s.rdoc_options = ['--charset=UTF-8']
|
45
45
|
s.extra_rdoc_files = ['README.md']
|
46
|
+
s.add_development_dependency 'codecov', '0.2.11'
|
46
47
|
s.add_development_dependency 'minitest', '5.11.3'
|
47
|
-
s.add_development_dependency 'rake', '12.3.
|
48
|
-
s.add_development_dependency 'rdoc', '
|
48
|
+
s.add_development_dependency 'rake', '12.3.3'
|
49
|
+
s.add_development_dependency 'rdoc', '6.3.1'
|
49
50
|
s.add_development_dependency 'rubocop', '0.62.0'
|
50
51
|
s.add_development_dependency 'rubocop-rspec', '1.31.0'
|
51
52
|
end
|
data/lib/iri.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2019-2021 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -42,14 +42,22 @@ require 'cgi'
|
|
42
42
|
# {README}[https://github.com/yegor256/iri/blob/master/README.md] file.
|
43
43
|
#
|
44
44
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
45
|
-
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
|
45
|
+
# Copyright:: Copyright (c) 2019-2021 Yegor Bugayenko
|
46
46
|
# License:: MIT
|
47
47
|
class Iri
|
48
|
+
# When URI is not valid.
|
49
|
+
class InvalidURI < StandardError; end
|
50
|
+
|
48
51
|
# Makes a new object.
|
49
52
|
#
|
50
53
|
# You can even ignore the argument, which will produce an empty URI.
|
51
|
-
|
52
|
-
|
54
|
+
#
|
55
|
+
# By default, this class will never throw any exceptions, even if your URI
|
56
|
+
# is not valid. It will just assume that the URI is"/". However,
|
57
|
+
# you can turn this mode off, by specifying safe as FALSE.
|
58
|
+
def initialize(uri = '', safe: true)
|
59
|
+
@uri = uri
|
60
|
+
@safe = safe
|
53
61
|
end
|
54
62
|
|
55
63
|
# Convert it to a string.
|
@@ -59,10 +67,12 @@ class Iri
|
|
59
67
|
|
60
68
|
# Convert it to an object of class +URI+.
|
61
69
|
def to_uri
|
62
|
-
|
70
|
+
the_uri.clone
|
63
71
|
end
|
64
72
|
|
65
|
-
# Add a few query arguments.
|
73
|
+
# Add a few query arguments.
|
74
|
+
#
|
75
|
+
# For example:
|
66
76
|
#
|
67
77
|
# Iri.new('https://google.com').add(q: 'test', limit: 10)
|
68
78
|
#
|
@@ -81,7 +91,9 @@ class Iri
|
|
81
91
|
end
|
82
92
|
end
|
83
93
|
|
84
|
-
# Delete a few query arguments.
|
94
|
+
# Delete a few query arguments.
|
95
|
+
#
|
96
|
+
# For example:
|
85
97
|
#
|
86
98
|
# Iri.new('https://google.com?q=test').del(:q)
|
87
99
|
#
|
@@ -148,7 +160,9 @@ class Iri
|
|
148
160
|
end
|
149
161
|
end
|
150
162
|
|
151
|
-
# Remove the entire path+query+fragment part.
|
163
|
+
# Remove the entire path+query+fragment part.
|
164
|
+
#
|
165
|
+
# For example:
|
152
166
|
#
|
153
167
|
# Iri.new('https://google.com/a/b?q=test').cut('/hello')
|
154
168
|
#
|
@@ -161,28 +175,40 @@ class Iri
|
|
161
175
|
end
|
162
176
|
end
|
163
177
|
|
164
|
-
# Append something new to the path
|
178
|
+
# Append something new to the path.
|
179
|
+
#
|
180
|
+
# For example:
|
165
181
|
#
|
166
182
|
# Iri.new('https://google.com/a/b?q=test').append('/hello')
|
167
183
|
#
|
168
184
|
# The result will contain "https://google.com/a/b/hello?q=test".
|
169
185
|
def append(part)
|
170
186
|
modify do |c|
|
171
|
-
|
187
|
+
tail = (c.path.end_with?('/') ? '' : '/') + CGI.escape(part.to_s)
|
188
|
+
c.path = c.path + tail
|
172
189
|
end
|
173
190
|
end
|
174
191
|
|
175
192
|
private
|
176
193
|
|
194
|
+
def the_uri
|
195
|
+
@the_uri ||= URI(@uri)
|
196
|
+
rescue URI::InvalidURIError => e
|
197
|
+
raise InvalidURI, e.message unless @safe
|
198
|
+
@the_uri = URI('/')
|
199
|
+
end
|
200
|
+
|
177
201
|
def modify
|
178
|
-
c =
|
202
|
+
c = the_uri.clone
|
179
203
|
yield c
|
180
204
|
Iri.new(c)
|
181
205
|
end
|
182
206
|
|
183
207
|
def modify_query
|
184
208
|
modify do |c|
|
185
|
-
params = CGI.parse(
|
209
|
+
params = CGI.parse(the_uri.query || '').map do |p, a|
|
210
|
+
[p.to_s, a.clone]
|
211
|
+
end.to_h
|
186
212
|
yield(params)
|
187
213
|
c.query = URI.encode_www_form(params)
|
188
214
|
end
|
data/logo.svg
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<svg width="314px" height="314px" viewBox="0 0 314 314" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
3
|
+
<!-- Generator: Sketch 43.2 (39069) - http://www.bohemiancoding.com/sketch -->
|
4
|
+
<title>Group 2</title>
|
5
|
+
<desc>Created with Sketch.</desc>
|
6
|
+
<defs></defs>
|
7
|
+
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
8
|
+
<g id="Group-2">
|
9
|
+
<g id="Group">
|
10
|
+
<circle id="Oval" fill="#053C5E" cx="157" cy="157" r="157"></circle>
|
11
|
+
<rect id="Rectangle" fill="#2B2B2B" x="0" y="233" width="184" height="69"></rect>
|
12
|
+
<text id="iri" font-family="CourierNewPS-BoldMT, Courier New" font-size="60" font-weight="bold" fill="#FFFFFF">
|
13
|
+
<tspan x="38.4912109" y="281">iri</tspan>
|
14
|
+
</text>
|
15
|
+
<path d="M135.676765,111.215287 C135.211714,113.540467 132.770932,120.688823 130.252813,127.100603 C127.734621,133.512383 125.2898,140.431445 124.819828,142.476214 C123.6868,147.405663 121.517836,147.185477 119.69487,141.95608 C116.899865,133.938362 105.171362,111.043501 103.859129,111.043501 C100.420089,111.043501 101.508757,114.986149 109.1771,130.30227 C113.739327,139.414532 118.032086,147.448041 118.716515,148.15443 C120.694817,150.196115 120.172626,154.319657 117.358599,158.877992 C113.567467,165.019055 107.570942,183.721189 108.054206,187.896804 C108.804956,194.383204 112.436054,192.210274 113.355359,184.724515 C114.48376,175.535577 120.945556,159.641154 124.897459,156.333653 C127.109021,154.482778 128.268636,151.905536 128.573284,148.163978 C128.818001,145.157747 131.906711,135.560972 135.437115,126.837819 C138.96752,118.114666 141.511492,110.079835 141.090434,108.982574 C139.755727,105.504315 136.554941,106.824333 135.676765,111.215287 M174.714659,126.841564 C169.37392,129.699438 169.197653,130.049915 167.452978,141.283475 C165.577352,153.360398 165.225112,168.513913 166.548289,180.203784 L167.566817,189.202501 L161.346213,191.9541 C154.601949,194.937416 150.91195,200.302465 153.156708,203.861146 C155.104824,206.949562 157.09025,206.70198 157.571826,203.310532 C158.083734,199.706169 166.097413,193.204052 170.29418,192.987978 C172.116999,192.894116 173.522874,191.717021 173.97823,189.903529 C174.383277,188.290613 177.740353,184.944554 181.438431,182.467858 C188.546172,177.707551 194.317883,170.450278 194.317883,166.273341 C194.317883,162.684548 189.493165,158.361603 185.487795,158.361603 C180.701636,158.361603 180.027195,155.239403 183.731222,150.229385 C188.308065,144.038966 188.284856,130.867646 183.690534,127.147387 C179.896537,124.075276 179.885006,124.074836 174.714659,126.841564 M182.67318,134.240439 C184.752542,140.153164 174.808961,161.185104 171.588639,157.68562 C169.868715,155.81653 172.863122,135.012708 175.266374,132.134564 C177.872553,129.013319 181.163896,129.949075 182.67318,134.240439 M184.854262,162.269586 C190.589839,163.855621 189.673839,167.881335 181.645765,176.371155 C177.281618,180.986262 173.904933,183.573859 173.371946,182.711474 C172.876636,181.91012 172.127869,176.711937 171.707987,171.159972 L170.944531,161.065463 L176.209475,161.200234 C179.105172,161.274339 182.995308,161.755548 184.854262,162.269586 M132.642184,172.492256 C131.593837,175.224098 133.152917,177.288844 136.264027,177.288844 C139.014965,177.288844 139.431396,176.221769 138.067531,172.667568 C137.039234,169.987871 133.645289,169.878218 132.642184,172.492256 M203.781503,185.840798 C203.781503,187.657595 209.264724,193.512152 210.966361,193.512152 C212.534035,193.512152 211.991059,187.391138 210.270768,185.670847 C208.092403,183.492409 203.781503,183.605293 203.781503,185.840798" id="Fill-6" fill="#427B8A" fill-rule="nonzero"></path>
|
16
|
+
</g>
|
17
|
+
</g>
|
18
|
+
</g>
|
19
|
+
</svg>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2019-2021 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
|
23
|
+
STDOUT.sync = true
|
24
|
+
|
25
|
+
require 'simplecov'
|
26
|
+
SimpleCov.start
|
27
|
+
if ENV['CI'] == 'true'
|
28
|
+
require 'codecov'
|
29
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
30
|
+
end
|
data/test/test_iri.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2019 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2019-2021 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -27,7 +27,7 @@ require_relative '../lib/iri'
|
|
27
27
|
|
28
28
|
# Iri test.
|
29
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
|
30
|
+
# Copyright:: Copyright (c) 2019-2021 Yegor Bugayenko
|
31
31
|
# License:: MIT
|
32
32
|
class IriTest < Minitest::Test
|
33
33
|
def test_builds_uri
|
@@ -43,6 +43,16 @@ class IriTest < Minitest::Test
|
|
43
43
|
assert_equal('https://localhost:443/?q=books+about+tennis&limit=10', url)
|
44
44
|
end
|
45
45
|
|
46
|
+
def test_broken_uri
|
47
|
+
assert_raises Iri::InvalidURI do
|
48
|
+
Iri.new('https://example.com/>', safe: false).add(a: 1)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_broken_uri_in_safe_mode
|
53
|
+
Iri.new('https://example.com/>>>').add(a: 1)
|
54
|
+
end
|
55
|
+
|
46
56
|
def test_starts_with_empty_uri
|
47
57
|
assert_equal(
|
48
58
|
'https:',
|
@@ -128,6 +138,24 @@ class IriTest < Minitest::Test
|
|
128
138
|
)
|
129
139
|
end
|
130
140
|
|
141
|
+
def test_appends_to_empty_ending
|
142
|
+
assert_equal(
|
143
|
+
'http://google.com/hello',
|
144
|
+
Iri.new('http://google.com/').append('hello').to_s
|
145
|
+
)
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_appends_empty_path
|
149
|
+
assert_equal(
|
150
|
+
'http://google.com/hello/',
|
151
|
+
Iri.new('http://google.com/hello').append('').append('').to_s
|
152
|
+
)
|
153
|
+
assert_equal(
|
154
|
+
'http://google.com/test',
|
155
|
+
Iri.new('http://google.com/hello').cut.append('test').to_s
|
156
|
+
)
|
157
|
+
end
|
158
|
+
|
131
159
|
def test_replaces_query_param
|
132
160
|
assert_equal(
|
133
161
|
'http://google/?a=hey&b=2&c=3',
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: codecov
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.11
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.11
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: minitest
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,28 +44,28 @@ dependencies:
|
|
30
44
|
requirements:
|
31
45
|
- - '='
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 12.3.
|
47
|
+
version: 12.3.3
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - '='
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 12.3.
|
54
|
+
version: 12.3.3
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rdoc
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - '='
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 6.3.1
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - '='
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 6.3.1
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rubocop
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,13 +110,16 @@ files:
|
|
96
110
|
- ".rultor.yml"
|
97
111
|
- ".travis.yml"
|
98
112
|
- Gemfile
|
113
|
+
- LICENSE.txt
|
99
114
|
- README.md
|
100
115
|
- Rakefile
|
101
116
|
- appveyor.yml
|
102
117
|
- iri.gemspec
|
103
118
|
- lib/iri.rb
|
119
|
+
- logo.svg
|
120
|
+
- test/test__helper.rb
|
104
121
|
- test/test_iri.rb
|
105
|
-
homepage:
|
122
|
+
homepage: https://github.com/yegor256/iri
|
106
123
|
licenses:
|
107
124
|
- MIT
|
108
125
|
metadata: {}
|
@@ -115,16 +132,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
132
|
requirements:
|
116
133
|
- - ">="
|
117
134
|
- !ruby/object:Gem::Version
|
118
|
-
version: '2.
|
135
|
+
version: '2.2'
|
119
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
137
|
requirements:
|
121
138
|
- - ">="
|
122
139
|
- !ruby/object:Gem::Version
|
123
140
|
version: '0'
|
124
141
|
requirements: []
|
125
|
-
rubygems_version: 3.
|
142
|
+
rubygems_version: 3.1.2
|
126
143
|
signing_key:
|
127
144
|
specification_version: 2
|
128
145
|
summary: Simple Immutable Ruby URI Builder
|
129
146
|
test_files:
|
147
|
+
- test/test__helper.rb
|
130
148
|
- test/test_iri.rb
|