uri-query_params 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da86f32384123e5240b11aae3767b48770696604afb3eee3c4a04351badaa585
4
- data.tar.gz: c469674aa5d7f20e72f19dd6fb2eac80917182638706390fe1cc2e60d89ecb98
3
+ metadata.gz: cc67bd83bfc5a5da2b33ddb21f124663d45e54ce09498b541f223a6180851236
4
+ data.tar.gz: 692d674b03b6e0e165c4ee5cd78363b9e7288ac428d4972c69de8f90379668fc
5
5
  SHA512:
6
- metadata.gz: 62031ef7a85c4e0d17205964f3d2b14c0596d42da4c04f583faedd83f8a7f3c861bddfefdae6e4c36055913e2a59738a93021d943bd0447d91cf360d3762b8b3
7
- data.tar.gz: af4ad8d768e9114636279f4abe2d197b439f856474bab5dbb5269388e8f5ad7aaa0a780858e16c797d77f68874f696d3c2e58e486dfada640bcbe19b826b4e3e
6
+ metadata.gz: cb4d13c217fabbd2abe86abab5a4bdce9c7039430967c955cac58d9eb06584c29dfd7cbdfefe04250d6670936f28bae2d619ea4bb9a9c762ba5ac005bb83d1f4
7
+ data.tar.gz: 902d5196f48db8853c9f60110039ffc0fa41835c6877dac60798f69ea3a5e0f063c5cc321f5d8bae3635ddd41d00920edd3ee87cd24ab1eee46e32a78e285d29
@@ -9,8 +9,6 @@ jobs:
9
9
  fail-fast: false
10
10
  matrix:
11
11
  ruby:
12
- - 2.6
13
- - 2.7
14
12
  - '3.0'
15
13
  - 3.1
16
14
  - jruby
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  /Gemfile.lock
2
+ /coverage/
2
3
  /doc/
3
4
  /pkg/
4
5
  /vendor/bundle
data/ChangeLog.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.8.1 / 2022-10-22
2
+
3
+ * Updated {URI::Generic#to_s} to ruby-3.0.0.
4
+ * Override {URI::HTTP#request_uri} to be aware of
5
+ {URI::QueryParams::Mixin#query_params}.
6
+
1
7
  ### 0.8.0 / 2022-01-14
2
8
 
3
9
  * Require [ruby] >= 2.0.0.
data/Gemfile CHANGED
@@ -10,7 +10,8 @@ group :development do
10
10
  gem 'rake'
11
11
  gem 'rubygems-tasks', '~> 0.2'
12
12
 
13
- gem 'rspec', '~> 3.0'
13
+ gem 'rspec', '~> 3.0'
14
+ gem 'simplecov', '~> 0.20'
14
15
 
15
16
  gem 'kramdown'
16
17
  gem 'yard', '~> 0.9'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri/query_params/mixin'
2
4
 
3
5
  require 'uri/generic'
@@ -11,44 +13,44 @@ module URI
11
13
  # Constructs String from URI
12
14
  #
13
15
  # @note
14
- # This is the `URI::Generic#to_s` method from Ruby 2.2.0, with the minor
16
+ # This is the `URI::Generic#to_s` method from Ruby 3.0.0, with the minor
15
17
  # modification of calling the `query` method overrode by
16
18
  # {URI::QueryParams::Mixin}, instead of `@query`.
17
19
  #
18
- # @see https://github.com/ruby/ruby/blob/v2_2_0/lib/uri/generic.rb#L1338-L1376
20
+ # @see https://github.com/ruby/ruby/blob/v3_0.0/lib/uri/generic.rb#L1330-L1368
19
21
  #
20
22
  def to_s
21
- str = ''
23
+ str = ''.dup
22
24
  if @scheme
23
25
  str << @scheme
24
- str << ':'.freeze
26
+ str << ':'
25
27
  end
26
28
 
27
29
  if @opaque
28
30
  str << @opaque
29
31
  else
30
- if @host
31
- str << '//'.freeze
32
+ if @host || %w[file postgres].include?(@scheme)
33
+ str << '//'
32
34
  end
33
35
  if self.userinfo
34
36
  str << self.userinfo
35
- str << '@'.freeze
37
+ str << '@'
36
38
  end
37
39
  if @host
38
40
  str << @host
39
41
  end
40
42
  if @port && @port != self.default_port
41
- str << ':'.freeze
43
+ str << ':'
42
44
  str << @port.to_s
43
45
  end
44
46
  str << @path
45
- if query
46
- str << '?'.freeze
47
+ if (query = self.query)
48
+ str << '?'
47
49
  str << query
48
50
  end
49
51
  end
50
52
  if @fragment
51
- str << '#'.freeze
53
+ str << '#'
52
54
  str << @fragment
53
55
  end
54
56
  str
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri/query_params/core_ext/uri/generic'
4
+
5
+ require 'uri/http'
6
+
7
+ module URI
8
+ class HTTP < Generic
9
+
10
+ alias raw_request_uri request_uri
11
+
12
+ #
13
+ # Returns the full path for an HTTP request.
14
+ #
15
+ # @return [String, nil]
16
+ # The request URI (path + query params) or `nil` if the URI has no
17
+ # path.
18
+ #
19
+ # @example
20
+ # uri.path = '/path'
21
+ # uri.query_params['foo'] = '1'
22
+ # uri.query_params['bar'] = '2'
23
+ # uri.request_uri
24
+ # # => "/path?foo=1&bar=2"
25
+ #
26
+ def request_uri
27
+ if defined?(@query_params) && @query_params
28
+ return unless @path
29
+
30
+ query = URI::QueryParams.dump(@query_params)
31
+
32
+ url = "#{@path}?#{query}"
33
+ url = "/#{url}" unless url.start_with?('/')
34
+ url
35
+ else
36
+ raw_request_uri
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -1 +1,2 @@
1
1
  require 'uri/query_params/core_ext/uri/generic'
2
+ require 'uri/query_params/core_ext/uri/http'
@@ -1,6 +1,6 @@
1
1
  module URI
2
2
  module QueryParams
3
3
  # uri-query_params version
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.1'
5
5
  end
6
6
  end
@@ -1,2 +1,2 @@
1
1
  require 'uri/query_params/query_params'
2
- require 'uri/query_params/extensions'
2
+ require 'uri/query_params/core_ext'
@@ -3,7 +3,7 @@ require 'query_params_mixin_examples'
3
3
  require 'uri/query_params/core_ext/addressable/uri'
4
4
 
5
5
  describe Addressable::URI do
6
- let(:uri) { described_class.parse('http://www.example.com/page.php') }
6
+ subject { described_class.parse('http://www.example.com/page.php') }
7
7
 
8
8
  it_should_behave_like "URI::QueryParams::Mixin"
9
9
  end
@@ -3,7 +3,7 @@ require 'query_params_mixin_examples'
3
3
  require 'uri/query_params/core_ext/uri'
4
4
 
5
5
  describe URI::Generic do
6
- let(:uri) { URI('/page.php') }
6
+ subject { URI.parse('/page.php') }
7
7
 
8
8
  it_should_behave_like "URI::QueryParams::Mixin"
9
9
  end
@@ -1,9 +1,77 @@
1
1
  require 'spec_helper'
2
2
  require 'query_params_mixin_examples'
3
- require 'uri/query_params/core_ext/uri'
3
+ require 'uri/query_params/core_ext/uri/http'
4
4
 
5
5
  describe URI::HTTP do
6
- let(:uri) { URI('http://www.example.com/page.php') }
6
+ subject { URI.parse("http://www.example.com/page.php") }
7
7
 
8
8
  it_should_behave_like "URI::QueryParams::Mixin"
9
+
10
+ describe "#request_uri" do
11
+ context "when #query_params is set" do
12
+ let(:query_params) do
13
+ {'x' => '1', 'y' => '2'}
14
+ end
15
+
16
+ before { subject.query_params = query_params }
17
+
18
+ context "and when #path is set" do
19
+ it "must return the #path and #query_params" do
20
+ expect(subject.request_uri).to eq("#{subject.path}?x=#{query_params['x']}&y=#{query_params['y']}")
21
+ end
22
+
23
+ context "but #path does not start with a '/' character" do
24
+ subject { URI.parse("http://www.example.com") }
25
+
26
+ it "must prepend a '/' character" do
27
+ expect(subject.request_uri).to eq("/#{subject.path}?x=#{query_params['x']}&y=#{query_params['y']}")
28
+ end
29
+ end
30
+ end
31
+
32
+ context "but #path is not set" do
33
+ before { subject.path = nil }
34
+
35
+ it "must return nil" do
36
+ expect(subject.request_uri).to be(nil)
37
+ end
38
+ end
39
+ end
40
+
41
+ context "when #query_params is not set" do
42
+ context "and when #path is set" do
43
+ context "and when #query is set" do
44
+ let(:query) { 'x=1&y=2' }
45
+
46
+ subject { URI("http://www.example.com/page.php?#{query}") }
47
+
48
+ it "must return the #path and #query" do
49
+ expect(subject.request_uri).to eq("#{subject.path}?#{subject.query}")
50
+ end
51
+ end
52
+
53
+ context "but when #query is not set" do
54
+ it "must return #path" do
55
+ expect(subject.request_uri).to eq(subject.path)
56
+ end
57
+ end
58
+
59
+ context "but #path does not start with a '/' character" do
60
+ subject { URI.parse("http://www.example.com") }
61
+
62
+ it "must prepend a '/' character" do
63
+ expect(subject.request_uri).to eq("/#{subject.path}")
64
+ end
65
+ end
66
+ end
67
+
68
+ context "but #path is not set" do
69
+ before { subject.path = nil }
70
+
71
+ it "must return nil" do
72
+ expect(subject.request_uri).to be(nil)
73
+ end
74
+ end
75
+ end
76
+ end
9
77
  end
@@ -6,9 +6,7 @@ require 'uri'
6
6
  shared_examples_for "URI::QueryParams::Mixin" do
7
7
  let(:query) { 'x=1&y=one%20two&z' }
8
8
 
9
- subject { uri }
10
-
11
- before(:each) { uri.query = query }
9
+ before { subject.query = query }
12
10
 
13
11
  context "when included" do
14
12
  it "should include QueryParams::Mixin" do
@@ -16,11 +14,11 @@ shared_examples_for "URI::QueryParams::Mixin" do
16
14
  end
17
15
 
18
16
  it "should still provide access to #query" do
19
- expect(uri.query).to eq(query)
17
+ expect(subject.query).to eq(query)
20
18
  end
21
19
 
22
20
  it "should provide #query_params" do
23
- is_expected.to respond_to(:query_params)
21
+ expect(subject).to respond_to(:query_params)
24
22
  end
25
23
  end
26
24
 
@@ -44,6 +42,7 @@ shared_examples_for "URI::QueryParams::Mixin" do
44
42
  describe "#query" do
45
43
  it "should dump out the #query_params when accessing #query" do
46
44
  subject.query_params = {'u' => '3'}
45
+
47
46
  expect(subject.query).to eq('u=3')
48
47
  end
49
48
 
@@ -61,26 +60,24 @@ shared_examples_for "URI::QueryParams::Mixin" do
61
60
  end
62
61
 
63
62
  describe "#query_params" do
64
- subject { uri.query_params }
65
-
66
63
  it "should be a Hash" do
67
- expect(subject.class).to eq(Hash)
64
+ expect(subject.query_params.class).to eq(Hash)
68
65
  end
69
66
 
70
67
  it "should contain params" do
71
- is_expected.not_to be_empty
68
+ expect(subject.query_params).not_to be_empty
72
69
  end
73
70
 
74
71
  it "can contain single-word params" do
75
- expect(subject['x']).to eq('1')
72
+ expect(subject.query_params['x']).to eq('1')
76
73
  end
77
74
 
78
75
  it "can contain multi-word params" do
79
- expect(subject['y']).to eq('one two')
76
+ expect(subject.query_params['y']).to eq('one two')
80
77
  end
81
78
 
82
79
  it "can contain empty params" do
83
- expect(subject['z']).to be_empty
80
+ expect(subject.query_params['z']).to be_empty
84
81
  end
85
82
  end
86
83
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,4 @@
1
1
  require 'rspec'
2
+ require 'simplecov'
3
+
4
+ SimpleCov.start
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri-query_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-15 00:00:00.000000000 Z
11
+ date: 2022-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -49,6 +49,7 @@ files:
49
49
  - lib/uri/query_params/core_ext/addressable/uri.rb
50
50
  - lib/uri/query_params/core_ext/uri.rb
51
51
  - lib/uri/query_params/core_ext/uri/generic.rb
52
+ - lib/uri/query_params/core_ext/uri/http.rb
52
53
  - lib/uri/query_params/extensions.rb
53
54
  - lib/uri/query_params/extensions/addressable/uri.rb
54
55
  - lib/uri/query_params/extensions/uri.rb
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  - !ruby/object:Gem::Version
92
93
  version: '0'
93
94
  requirements: []
94
- rubygems_version: 3.2.22
95
+ rubygems_version: 3.3.7
95
96
  signing_key:
96
97
  specification_version: 4
97
98
  summary: Access the query parameters of a URI, just like $_GET in PHP.