iri 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/iri.gemspec +1 -1
  3. data/lib/iri.rb +17 -11
  4. data/test/test_iri.rb +5 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b0ead5ff4a49ffdb3c0dda53b2cd03d92746aa4a3338c0320b539be271e3f6b
4
- data.tar.gz: 5c1b3de33446ec5e6f88dd077511ec5bb210692d4891da434cdbc778dba0107a
3
+ metadata.gz: c9981ebf1f6a24c408671ca60df156211a1866a23c0ba2a5e8a7424dfb8461b4
4
+ data.tar.gz: f0bcbb8b78b70e14b1e6b42c7b141174aca57d00d0b1e33e101061bb10f12ee0
5
5
  SHA512:
6
- metadata.gz: 9d303b3a342e9d3f2517ae478f29ccbbd5bf4359afa7ed7237dd3e9b7991f9c060a6cc262f3af086364129d3b6de55901f42e0e9a3c42023539c6111fd3213d7
7
- data.tar.gz: 274c64e316691fd65e05b14cef70bf18929a37225e2511492988d501a4d68253727cda1788d4596b123c5520178af0a7915b2a7a2672aeba65eb071acc00fa75
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.9.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] safe SHould it safe?
64
- def initialize(uri = '', safe: true)
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
- @uri.to_s
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 [String] Local part of the URI
105
+ # @return [Iri] Iri with no host/port/scheme
95
106
  def to_local
96
- u = the_uri
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
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.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko