iri 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/iri.gemspec +1 -1
  4. data/lib/iri.rb +27 -0
  5. data/test/test_iri.rb +21 -0
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87b71f1b546b3b5c62641549af0c0a448dfee41109519f3a9987f9e67b916948
4
- data.tar.gz: 7102176c5f82ff8a05f5295233d74fff0d0e81400bf47f561763ee16d9916e60
3
+ metadata.gz: 12449f264a53cb485147418a1dac3bf592d6739bc9907a9150c742d67f0cea67
4
+ data.tar.gz: 47b3d56c0cf5f9b613fdb4902c98bd385cce90450271e9256ec5cab8ce2cfdfc
5
5
  SHA512:
6
- metadata.gz: 4c931d32c782208e17e613dd27a98eea60a320dacfb279f35d6c24e73bdf809344e8fed4b7e24b8d5be8967662d34c2e9af7ccdd02b20139b56d7e8a6a021421
7
- data.tar.gz: aed064a6106b224ce9cc063b36edbbc472e34050ce0207878c014fff0d793d42a9822a8488efba41dc769dabdcd71d1881f4eb19d5350c2d2bb86cd68b4c240d
6
+ metadata.gz: f4aa33c7601a7f6ea0f06e14a091d644efd48ee821198fedecf78bedbb34adba049d203cd2466f7f2562ed3344ea8d6a7e5462732c56c36872ac343611a25f29
7
+ data.tar.gz: 372918b261d96aa75a6c8f813ee315e7dc9a1a32e31343b5bbd2d54b325726771f5650bd86a7a87d76204300a19a20b31523fdc79a557b9bdb319d2a9cab2ce4
data/README.md CHANGED
@@ -12,6 +12,7 @@ Class `Iri` helps you build a URI and then modify its
12
12
  parts via a simple fluent interface:
13
13
 
14
14
  ```ruby
15
+ require 'iri'
15
16
  url = Iri.new('http://google.com/')
16
17
  .add(q: 'books about OOP', limit: 50)
17
18
  .del(:q) # remove this query parameter
@@ -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.1.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
@@ -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',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko