iri 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.0pdd.yml +9 -0
- data/.gitignore +6 -0
- data/.pdd +5 -0
- data/.rubocop.yml +21 -0
- data/.rultor.yml +26 -0
- data/.travis.yml +12 -0
- data/Gemfile +25 -0
- data/README.md +62 -0
- data/Rakefile +57 -0
- data/appveyor.yml +36 -0
- data/iri.gemspec +50 -0
- data/lib/iri.rb +120 -0
- data/test/test_iri.rb +91 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 87b71f1b546b3b5c62641549af0c0a448dfee41109519f3a9987f9e67b916948
|
4
|
+
data.tar.gz: 7102176c5f82ff8a05f5295233d74fff0d0e81400bf47f561763ee16d9916e60
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c931d32c782208e17e613dd27a98eea60a320dacfb279f35d6c24e73bdf809344e8fed4b7e24b8d5be8967662d34c2e9af7ccdd02b20139b56d7e8a6a021421
|
7
|
+
data.tar.gz: aed064a6106b224ce9cc063b36edbbc472e34050ce0207878c014fff0d793d42a9822a8488efba41dc769dabdcd71d1881f4eb19d5350c2d2bb86cd68b4c240d
|
data/.0pdd.yml
ADDED
data/.gitignore
ADDED
data/.pdd
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
TargetRubyVersion: 2.5
|
4
|
+
|
5
|
+
Metrics/ClassLength:
|
6
|
+
Exclude:
|
7
|
+
- 'test/*.rb'
|
8
|
+
Layout/EmptyLineAfterGuardClause:
|
9
|
+
Enabled: false
|
10
|
+
Layout/MultilineMethodCallIndentation:
|
11
|
+
Enabled: false
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Max: 30
|
14
|
+
Metrics/MethodLength:
|
15
|
+
Max: 30
|
16
|
+
Metrics/CyclomaticComplexity:
|
17
|
+
Max: 12
|
18
|
+
Metrics/PerceivedComplexity:
|
19
|
+
Max: 12
|
20
|
+
Layout/EndOfLine:
|
21
|
+
EnforcedStyle: lf
|
data/.rultor.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
assets:
|
2
|
+
rubygems.yml: zerocracy/home#assets/rubygems.yml
|
3
|
+
install: |-
|
4
|
+
export GEM_HOME=~/.ruby
|
5
|
+
export GEM_PATH=$GEM_HOME:$GEM_PATH
|
6
|
+
release:
|
7
|
+
script: |-
|
8
|
+
bundle install
|
9
|
+
bundle exec rake
|
10
|
+
rm -rf *.gem
|
11
|
+
sed -i "s/0\.0\.0/${tag}/g" iri.gemspec
|
12
|
+
git add iri.gemspec
|
13
|
+
git commit -m "Version set to ${tag}"
|
14
|
+
gem build iri.gemspec
|
15
|
+
chmod 0600 ../rubygems.yml
|
16
|
+
gem push *.gem --config-file ../rubygems.yml
|
17
|
+
commanders:
|
18
|
+
- yegor256
|
19
|
+
architect:
|
20
|
+
- yegor256
|
21
|
+
merge:
|
22
|
+
commanders: []
|
23
|
+
script: |-
|
24
|
+
bundle install
|
25
|
+
bundle exec rake
|
26
|
+
deploy: {}
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2019 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 NONINFRINGEMENT. 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
|
+
source 'https://rubygems.org'
|
24
|
+
ruby '~>2.3'
|
25
|
+
gemspec
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
[![EO principles respected here](http://www.elegantobjects.org/badge.svg)](http://www.elegantobjects.org)
|
2
|
+
[![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/iri)](http://www.rultor.com/p/yegor256/iri)
|
3
|
+
[![We recommend RubyMine](http://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/yegor256/iri.svg)](https://travis-ci.org/yegor256/iri)
|
6
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/5hj65olpn2tds4al?svg=true)](https://ci.appveyor.com/project/yegor256/iri)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/iri.svg)](http://badge.fury.io/rb/iri)
|
8
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/7018d2fe438103828685/maintainability)](https://codeclimate.com/github/yegor256/iri/maintainability)
|
9
|
+
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/iri/master/frames)
|
10
|
+
|
11
|
+
Class `Iri` helps you build a URI and then modify its
|
12
|
+
parts via a simple fluent interface:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
url = Iri.new('http://google.com/')
|
16
|
+
.add(q: 'books about OOP', limit: 50)
|
17
|
+
.del(:q) # remove this query parameter
|
18
|
+
.del('limit') # remove this one too
|
19
|
+
.over(q: 'books about tennis', limit: 10) # replace these params
|
20
|
+
.scheme('https') # replace 'http' with 'https'
|
21
|
+
.host('localhost') # replace the host name
|
22
|
+
.port('443') # replace the port
|
23
|
+
.to_s # convert it to a string
|
24
|
+
```
|
25
|
+
|
26
|
+
Install it:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
$ gem install iri
|
30
|
+
```
|
31
|
+
|
32
|
+
Or add this to your `Gemfile`:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
gem 'iri'
|
36
|
+
```
|
37
|
+
|
38
|
+
Pay attention, it is not a parser. The only functionality this gem provides
|
39
|
+
is _building_ URIs. It is very convenient to use inside
|
40
|
+
[HAML](http://haml.info/tutorial.html), for example:
|
41
|
+
|
42
|
+
```haml
|
43
|
+
- iri = Iri.new(request.url)
|
44
|
+
%a{href: iri.over(offset: offset + 10)} Next Page
|
45
|
+
%a{href: iri.over(offset: offset - 10)} Previous Page
|
46
|
+
```
|
47
|
+
|
48
|
+
That's it.
|
49
|
+
|
50
|
+
## How to contribute
|
51
|
+
|
52
|
+
Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
53
|
+
Make sure you build is green before you contribute
|
54
|
+
your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
|
55
|
+
[Bundler](https://bundler.io/) installed. Then:
|
56
|
+
|
57
|
+
```
|
58
|
+
$ bundle update
|
59
|
+
$ bundle exec rake
|
60
|
+
```
|
61
|
+
|
62
|
+
If it's clean and you don't see any error messages, submit your pull request.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2019 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 NONINFRINGEMENT. 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
|
+
require 'rubygems'
|
24
|
+
require 'rake'
|
25
|
+
require 'rake/clean'
|
26
|
+
|
27
|
+
CLEAN = FileList['coverage']
|
28
|
+
|
29
|
+
def name
|
30
|
+
@name ||= File.basename(Dir['*.gemspec'].first, '.*')
|
31
|
+
end
|
32
|
+
|
33
|
+
def version
|
34
|
+
Gem::Specification.load(Dir['*.gemspec'].first).version
|
35
|
+
end
|
36
|
+
|
37
|
+
task default: %i[clean test rubocop]
|
38
|
+
|
39
|
+
require 'rake/testtask'
|
40
|
+
Rake::TestTask.new do |test|
|
41
|
+
test.libs << 'lib' << 'test'
|
42
|
+
test.pattern = 'test/**/test_*.rb'
|
43
|
+
test.verbose = false
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'rdoc/task'
|
47
|
+
RDoc::Task.new do |rdoc|
|
48
|
+
rdoc.main = 'README.md'
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.rdoc_files.include('README.md', 'lib/**/*.rb')
|
51
|
+
end
|
52
|
+
|
53
|
+
require 'rubocop/rake_task'
|
54
|
+
RuboCop::RakeTask.new do |task|
|
55
|
+
task.fail_on_error = true
|
56
|
+
task.requires << 'rubocop-rspec'
|
57
|
+
end
|
data/appveyor.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
version: '{build}'
|
2
|
+
skip_tags: true
|
3
|
+
clone_depth: 10
|
4
|
+
branches:
|
5
|
+
only:
|
6
|
+
- master
|
7
|
+
except:
|
8
|
+
- gh-pages
|
9
|
+
os: Windows Server 2012
|
10
|
+
environment:
|
11
|
+
matrix:
|
12
|
+
- ruby_version: "25-x64"
|
13
|
+
install:
|
14
|
+
- ps: |
|
15
|
+
$Env:PATH = "C:\Ruby${Env:ruby_version}\bin;${Env:PATH}"
|
16
|
+
if ($Env:ruby_version -match "^23" ) {
|
17
|
+
# RubyInstaller; download OpenSSL headers from OpenKnapsack Project
|
18
|
+
$Env:openssl_dir = "C:\Ruby${Env:ruby_version}"
|
19
|
+
appveyor DownloadFile http://dl.bintray.com/oneclick/OpenKnapsack/x64/openssl-1.0.2j-x64-windows.tar.lzma
|
20
|
+
7z e openssl-1.0.2j-x64-windows.tar.lzma
|
21
|
+
7z x -y -oC:\Ruby${Env:ruby_version} openssl-1.0.2j-x64-windows.tar
|
22
|
+
} else {
|
23
|
+
# RubyInstaller2; openssl package seems to be installed already
|
24
|
+
$Env:openssl_dir = "C:\msys64\mingw64"
|
25
|
+
}
|
26
|
+
- bundle config --local path vendor/bundle
|
27
|
+
- bundle config build.openssl --with-openssl-dir=%openssl_dir%
|
28
|
+
- ruby -v
|
29
|
+
- bundle -v
|
30
|
+
build_script:
|
31
|
+
- bundle update
|
32
|
+
- bundle install
|
33
|
+
test_script:
|
34
|
+
- bundle exec rake --quiet
|
35
|
+
cache:
|
36
|
+
- vendor/bundle
|
data/iri.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2019 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'English'
|
26
|
+
Gem::Specification.new do |s|
|
27
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
28
|
+
if s.respond_to? :required_rubygems_version=
|
29
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 0')
|
30
|
+
end
|
31
|
+
s.rubygems_version = '2.5'
|
32
|
+
s.required_ruby_version = '>=2.5'
|
33
|
+
s.name = 'iri'
|
34
|
+
s.version = '0.1.0'
|
35
|
+
s.license = 'MIT'
|
36
|
+
s.summary = 'Simple Immutable Ruby URI Builder'
|
37
|
+
s.description = 'Simple Immutable Ruby URI Builder'
|
38
|
+
s.authors = ['Yegor Bugayenko']
|
39
|
+
s.email = 'yegor256@gmail.com'
|
40
|
+
s.homepage = 'http://github.com/yegor256/iri'
|
41
|
+
s.files = `git ls-files`.split($RS)
|
42
|
+
s.test_files = s.files.grep(%r{^(test)/})
|
43
|
+
s.rdoc_options = ['--charset=UTF-8']
|
44
|
+
s.extra_rdoc_files = ['README.md']
|
45
|
+
s.add_development_dependency 'minitest', '5.11.3'
|
46
|
+
s.add_development_dependency 'rake', '12.3.1'
|
47
|
+
s.add_development_dependency 'rdoc', '4.3.0'
|
48
|
+
s.add_development_dependency 'rubocop', '0.62.0'
|
49
|
+
s.add_development_dependency 'rubocop-rspec', '1.31.0'
|
50
|
+
end
|
data/lib/iri.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2019 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'uri'
|
26
|
+
require 'cgi'
|
27
|
+
|
28
|
+
# It is a simple URI builder.
|
29
|
+
#
|
30
|
+
# require 'iri'
|
31
|
+
# url = Iri.new('http://google.com/')
|
32
|
+
# .add(q: 'books about OOP', limit: 50)
|
33
|
+
# .del(:q) // remove this query parameter
|
34
|
+
# .del('limit') // remove this one too
|
35
|
+
# .over(q: 'books about tennis', limit: 10) // replace these params
|
36
|
+
# .scheme('https')
|
37
|
+
# .host('localhost')
|
38
|
+
# .port('443')
|
39
|
+
# .to_s
|
40
|
+
#
|
41
|
+
# For more information read
|
42
|
+
# {README}[https://github.com/yegor256/iri/blob/master/README.md] file.
|
43
|
+
#
|
44
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
45
|
+
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
|
46
|
+
# License:: MIT
|
47
|
+
class Iri
|
48
|
+
# Makes a new object.
|
49
|
+
def initialize(uri)
|
50
|
+
@uri = URI(uri)
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_s
|
54
|
+
@uri.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_uri
|
58
|
+
@uri.clone
|
59
|
+
end
|
60
|
+
|
61
|
+
def add(hash)
|
62
|
+
modify_query do |params|
|
63
|
+
hash.each do |k, v|
|
64
|
+
params[k.to_s] = [] unless params[k.to_s]
|
65
|
+
params[k.to_s] << v
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def del(*keys)
|
71
|
+
modify_query do |params|
|
72
|
+
keys.each do |k|
|
73
|
+
params.delete(k.to_s)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def over(hash)
|
79
|
+
modify_query do |params|
|
80
|
+
hash.each do |k, v|
|
81
|
+
params[k.to_s] = [] unless params[k]
|
82
|
+
params[k.to_s] = [v]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def scheme(val)
|
88
|
+
modify do |c|
|
89
|
+
c.scheme = val
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def host(val)
|
94
|
+
modify do |c|
|
95
|
+
c.host = val
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def port(val)
|
100
|
+
modify do |c|
|
101
|
+
c.port = val
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def modify
|
108
|
+
c = @uri.clone
|
109
|
+
yield c
|
110
|
+
Iri.new(c)
|
111
|
+
end
|
112
|
+
|
113
|
+
def modify_query
|
114
|
+
modify do |c|
|
115
|
+
params = CGI.parse(@uri.query || '').map { |p, a| [p.to_s, a.clone] }.to_h
|
116
|
+
yield(params)
|
117
|
+
c.query = URI.encode_www_form(params)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/test/test_iri.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2019 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require_relative '../lib/iri'
|
27
|
+
|
28
|
+
# Iri test.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2019 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
class IriTest < Minitest::Test
|
33
|
+
def test_builds_uri
|
34
|
+
url = Iri.new('http://google.com/')
|
35
|
+
.add(q: 'books about OOP', limit: 50)
|
36
|
+
.del(:q)
|
37
|
+
.del('limit')
|
38
|
+
.over(q: 'books about tennis', limit: 10)
|
39
|
+
.scheme('https')
|
40
|
+
.host('localhost')
|
41
|
+
.port('443')
|
42
|
+
.to_s
|
43
|
+
assert_equal('https://localhost:443/?q=books+about+tennis&limit=10', url)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_replaces_scheme
|
47
|
+
assert_equal(
|
48
|
+
'https://google.com/',
|
49
|
+
Iri.new('http://google.com/').scheme('https').to_s
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_replaces_host
|
54
|
+
assert_equal(
|
55
|
+
'http://localhost/',
|
56
|
+
Iri.new('http://google.com/').host('localhost').to_s
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_replaces_port
|
61
|
+
assert_equal(
|
62
|
+
'http://localhost:443/',
|
63
|
+
Iri.new('http://localhost/').port(443).to_s
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_adds_query_param
|
68
|
+
assert_equal(
|
69
|
+
'http://google/?a=1&a=3&b=2',
|
70
|
+
Iri.new('http://google/').add(a: 1, b: 2).add(a: 3).to_s
|
71
|
+
)
|
72
|
+
assert_equal(
|
73
|
+
'http://google/?%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82+%D0%B4%D1%80%D1%83%D0%B3=%D0%BA%D0%B0%D0%BA+%D0%B4%D0%B5%D0%BB%D0%B0%3F',
|
74
|
+
Iri.new('http://google/').add('привет друг' => 'как дела?').to_s
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_removes_query_param
|
79
|
+
assert_equal(
|
80
|
+
'http://google/?b=2&c=3',
|
81
|
+
Iri.new('http://google/?a=1&b=2&c=3&a=3').del('a').del('x').to_s
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_replaces_query_param
|
86
|
+
assert_equal(
|
87
|
+
'http://google/?a=hey&b=2&c=3',
|
88
|
+
Iri.new('http://google/?a=1&b=2&c=3&a=33').over(a: 'hey').to_s
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iri
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yegor Bugayenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.11.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.11.3
|
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.3.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.62.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.62.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.31.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.31.0
|
83
|
+
description: Simple Immutable Ruby URI Builder
|
84
|
+
email: yegor256@gmail.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files:
|
88
|
+
- README.md
|
89
|
+
files:
|
90
|
+
- ".0pdd.yml"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".pdd"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".rultor.yml"
|
95
|
+
- ".travis.yml"
|
96
|
+
- Gemfile
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- appveyor.yml
|
100
|
+
- iri.gemspec
|
101
|
+
- lib/iri.rb
|
102
|
+
- test/test_iri.rb
|
103
|
+
homepage: http://github.com/yegor256/iri
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options:
|
109
|
+
- "--charset=UTF-8"
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '2.5'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubygems_version: 3.0.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 2
|
126
|
+
summary: Simple Immutable Ruby URI Builder
|
127
|
+
test_files:
|
128
|
+
- test/test_iri.rb
|