uri-query_params 0.7.2 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +4 -9
- data/.gitignore +1 -0
- data/ChangeLog.md +14 -0
- data/Gemfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +26 -15
- data/gemspec.yml +9 -0
- data/lib/uri/query_params/core_ext/addressable/uri.rb +11 -0
- data/lib/uri/query_params/core_ext/uri/generic.rb +60 -0
- data/lib/uri/query_params/core_ext/uri/http.rb +41 -0
- data/lib/uri/query_params/core_ext/uri.rb +2 -0
- data/lib/uri/query_params/core_ext.rb +2 -0
- data/lib/uri/query_params/extensions/addressable/uri.rb +1 -11
- data/lib/uri/query_params/extensions/uri/generic.rb +1 -58
- data/lib/uri/query_params/extensions/uri.rb +1 -1
- data/lib/uri/query_params/extensions.rb +1 -2
- data/lib/uri/query_params/mixin.rb +2 -2
- data/lib/uri/query_params/query_params.rb +9 -24
- data/lib/uri/query_params/version.rb +1 -1
- data/lib/uri/query_params.rb +1 -1
- data/spec/{extensions → core_ext}/addressable/uri_spec.rb +2 -2
- data/spec/core_ext/uri/generic_spec.rb +9 -0
- data/spec/core_ext/uri/http_spec.rb +77 -0
- data/spec/extensions/addressable/uri.rb +13 -0
- data/spec/extensions/uri/generic_spec.rb +9 -5
- data/spec/extensions/uri_spec.rb +11 -0
- data/spec/extensions_spec.rb +11 -0
- data/spec/query_params_mixin_examples.rb +9 -12
- data/spec/spec_helper.rb +3 -0
- data/uri-query_params.gemspec +39 -105
- metadata +29 -16
- data/spec/extensions/uri/http_spec.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc67bd83bfc5a5da2b33ddb21f124663d45e54ce09498b541f223a6180851236
|
4
|
+
data.tar.gz: 692d674b03b6e0e165c4ee5cd78363b9e7288ac428d4972c69de8f90379668fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb4d13c217fabbd2abe86abab5a4bdce9c7039430967c955cac58d9eb06584c29dfd7cbdfefe04250d6670936f28bae2d619ea4bb9a9c762ba5ac005bb83d1f4
|
7
|
+
data.tar.gz: 902d5196f48db8853c9f60110039ffc0fa41835c6877dac60798f69ea3a5e0f063c5cc321f5d8bae3635ddd41d00920edd3ee87cd24ab1eee46e32a78e285d29
|
data/.github/workflows/ruby.yml
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
name: CI
|
2
2
|
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [ master ]
|
6
|
-
pull_request:
|
7
|
-
branches: ['**']
|
3
|
+
on: [ push, pull_request ]
|
8
4
|
|
9
5
|
jobs:
|
10
6
|
tests:
|
@@ -13,11 +9,10 @@ jobs:
|
|
13
9
|
fail-fast: false
|
14
10
|
matrix:
|
15
11
|
ruby:
|
16
|
-
-
|
17
|
-
-
|
18
|
-
- 2.6
|
19
|
-
- 2.7
|
12
|
+
- '3.0'
|
13
|
+
- 3.1
|
20
14
|
- jruby
|
15
|
+
- truffleruby
|
21
16
|
name: Ruby ${{ matrix.ruby }}
|
22
17
|
steps:
|
23
18
|
- uses: actions/checkout@v2
|
data/.gitignore
CHANGED
data/ChangeLog.md
CHANGED
@@ -1,3 +1,16 @@
|
|
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
|
+
|
7
|
+
### 0.8.0 / 2022-01-14
|
8
|
+
|
9
|
+
* Require [ruby] >= 2.0.0.
|
10
|
+
* Renamed `uri/query_params/extensions` to `uri/query_params/core_ext`.
|
11
|
+
* Removed legacy [ruby] 1.8 code.
|
12
|
+
* Fix instance variable warnings in `uri/query_params/mixin`.
|
13
|
+
|
1
14
|
### 0.7.2 / 2020-11-29
|
2
15
|
|
3
16
|
* Use `URI::DEFAULT_PARSER.escape` / `.unescape` instead of the deprecated
|
@@ -70,3 +83,4 @@
|
|
70
83
|
|
71
84
|
* Initial release.
|
72
85
|
|
86
|
+
[ruby]: https://www.ruby-lang.org/
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
* [Source](https://github.com/postmodern/uri-query_params)
|
4
4
|
* [Issues](https://github.com/postmodern/uri-query_params/issues)
|
5
5
|
* [Documentation](http://rubydoc.info/gems/uri-query_params/frames)
|
6
|
-
* [Email](mailto:postmodern.mod3 at gmail.com)
|
7
6
|
|
8
7
|
## Description
|
9
8
|
|
@@ -14,26 +13,36 @@ to `$_GET` from PHP, except available on any Ruby URI object.
|
|
14
13
|
|
15
14
|
Inspecting the URI query_params:
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
url = URI('http://www.google.com/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=1HY&q=bob+ross&btnG=Search')
|
20
|
-
url.query_params
|
21
|
-
# => {"btnG"=>"Search", "hs"=>"1HY", "rls"=>"org.mozilla:en-US:official", "client"=>"firefox-a", "hl"=>"en", "q"=>"bob+ross"}
|
16
|
+
```ruby
|
17
|
+
require 'uri/query_params'
|
22
18
|
|
23
|
-
|
24
|
-
|
19
|
+
url = URI('http://www.google.com/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=1HY&q=bob+ross&btnG=Search')
|
20
|
+
url.query_params
|
21
|
+
# => {"btnG"=>"Search", "hs"=>"1HY", "rls"=>"org.mozilla:en-US:official", "client"=>"firefox-a", "hl"=>"en", "q"=>"bob+ross"}
|
22
|
+
|
23
|
+
url.query_params['q']
|
24
|
+
# => "bob+ross"
|
25
|
+
```
|
25
26
|
|
26
27
|
Setting the URI query_params:
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
```ruby
|
30
|
+
url.query_params['q'] = 'Upright Citizens Brigade'
|
31
|
+
url.to_s
|
32
|
+
# => "http://www.google.com/search?btnG=Search&hs=1HY&rls=org.mozilla:en-US:official&client=firefox-a&hl=en&q=Upright%20Citizens%20Brigade"
|
33
|
+
```
|
31
34
|
|
32
35
|
Parsing URI query_params embedded within the Fragment Identifier:
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
```ruby
|
38
|
+
url = URI('https://twitter.com/#!/download?lang=en&logged_out=1')
|
39
|
+
URI(url.fragment).query_params
|
40
|
+
# => {"logged_out"=>"1", "lang"=>"en"}
|
41
|
+
```
|
42
|
+
|
43
|
+
## Requirements
|
44
|
+
|
45
|
+
* [ruby] >= 2.0.0
|
37
46
|
|
38
47
|
## Install
|
39
48
|
|
@@ -41,6 +50,8 @@ Parsing URI query_params embedded within the Fragment Identifier:
|
|
41
50
|
|
42
51
|
## License
|
43
52
|
|
44
|
-
Copyright (c) 2010-
|
53
|
+
Copyright (c) 2010-2022 Hal Brodigan
|
45
54
|
|
46
55
|
See {file:LICENSE.txt} for license information.
|
56
|
+
|
57
|
+
[ruby]: https://www.ruby-lang.org/
|
data/gemspec.yml
CHANGED
@@ -7,5 +7,14 @@ authors: Postmodern
|
|
7
7
|
email: postmodern.mod3@gmail.com
|
8
8
|
has_yard: true
|
9
9
|
|
10
|
+
metadata:
|
11
|
+
documentation_uri: https://rubydoc.info/gems/uri-query_params
|
12
|
+
source_code_uri: https://github.com/postmodern/uri-query_params.rb
|
13
|
+
bug_tracker_uri: https://github.com/postmodern/uri-query_params.rb/issues
|
14
|
+
changelog_uri: https://github.com/postmodern/uri-query_params.rb/blob/master/ChangeLog.md
|
15
|
+
rubygems_mfa_required: 'true'
|
16
|
+
|
17
|
+
required_ruby_version: ">= 2.0.0"
|
18
|
+
|
10
19
|
development_dependencies:
|
11
20
|
bundler: ~> 2.0
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri/query_params/mixin'
|
4
|
+
|
5
|
+
require 'uri/generic'
|
6
|
+
|
7
|
+
module URI
|
8
|
+
class Generic
|
9
|
+
|
10
|
+
include URI::QueryParams::Mixin
|
11
|
+
|
12
|
+
#
|
13
|
+
# Constructs String from URI
|
14
|
+
#
|
15
|
+
# @note
|
16
|
+
# This is the `URI::Generic#to_s` method from Ruby 3.0.0, with the minor
|
17
|
+
# modification of calling the `query` method overrode by
|
18
|
+
# {URI::QueryParams::Mixin}, instead of `@query`.
|
19
|
+
#
|
20
|
+
# @see https://github.com/ruby/ruby/blob/v3_0.0/lib/uri/generic.rb#L1330-L1368
|
21
|
+
#
|
22
|
+
def to_s
|
23
|
+
str = ''.dup
|
24
|
+
if @scheme
|
25
|
+
str << @scheme
|
26
|
+
str << ':'
|
27
|
+
end
|
28
|
+
|
29
|
+
if @opaque
|
30
|
+
str << @opaque
|
31
|
+
else
|
32
|
+
if @host || %w[file postgres].include?(@scheme)
|
33
|
+
str << '//'
|
34
|
+
end
|
35
|
+
if self.userinfo
|
36
|
+
str << self.userinfo
|
37
|
+
str << '@'
|
38
|
+
end
|
39
|
+
if @host
|
40
|
+
str << @host
|
41
|
+
end
|
42
|
+
if @port && @port != self.default_port
|
43
|
+
str << ':'
|
44
|
+
str << @port.to_s
|
45
|
+
end
|
46
|
+
str << @path
|
47
|
+
if (query = self.query)
|
48
|
+
str << '?'
|
49
|
+
str << query
|
50
|
+
end
|
51
|
+
end
|
52
|
+
if @fragment
|
53
|
+
str << '#'
|
54
|
+
str << @fragment
|
55
|
+
end
|
56
|
+
str
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -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,58 +1 @@
|
|
1
|
-
require 'uri/query_params/
|
2
|
-
|
3
|
-
require 'uri/generic'
|
4
|
-
|
5
|
-
module URI
|
6
|
-
class Generic
|
7
|
-
|
8
|
-
include URI::QueryParams::Mixin
|
9
|
-
|
10
|
-
#
|
11
|
-
# Constructs String from URI
|
12
|
-
#
|
13
|
-
# @note
|
14
|
-
# This is the `URI::Generic#to_s` method from Ruby 2.2.0, with the minor
|
15
|
-
# modification of calling the `query` method overrode by
|
16
|
-
# {URI::QueryParams::Mixin}, instead of `@query`.
|
17
|
-
#
|
18
|
-
# @see https://github.com/ruby/ruby/blob/v2_2_0/lib/uri/generic.rb#L1338-L1376
|
19
|
-
#
|
20
|
-
def to_s
|
21
|
-
str = ''
|
22
|
-
if @scheme
|
23
|
-
str << @scheme
|
24
|
-
str << ':'.freeze
|
25
|
-
end
|
26
|
-
|
27
|
-
if @opaque
|
28
|
-
str << @opaque
|
29
|
-
else
|
30
|
-
if @host
|
31
|
-
str << '//'.freeze
|
32
|
-
end
|
33
|
-
if self.userinfo
|
34
|
-
str << self.userinfo
|
35
|
-
str << '@'.freeze
|
36
|
-
end
|
37
|
-
if @host
|
38
|
-
str << @host
|
39
|
-
end
|
40
|
-
if @port && @port != self.default_port
|
41
|
-
str << ':'.freeze
|
42
|
-
str << @port.to_s
|
43
|
-
end
|
44
|
-
str << @path
|
45
|
-
if query
|
46
|
-
str << '?'.freeze
|
47
|
-
str << query
|
48
|
-
end
|
49
|
-
end
|
50
|
-
if @fragment
|
51
|
-
str << '#'.freeze
|
52
|
-
str << @fragment
|
53
|
-
end
|
54
|
-
str
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
1
|
+
require 'uri/query_params/core_ext/uri/generic'
|
@@ -1 +1 @@
|
|
1
|
-
require 'uri/query_params/
|
1
|
+
require 'uri/query_params/core_ext/uri'
|
@@ -1,2 +1 @@
|
|
1
|
-
require 'uri/query_params/
|
2
|
-
require 'uri/query_params/extensions/addressable/uri' if defined?(Addressable)
|
1
|
+
require 'uri/query_params/core_ext'
|
@@ -29,7 +29,7 @@ module URI
|
|
29
29
|
# @since 0.5.2
|
30
30
|
#
|
31
31
|
def query
|
32
|
-
if @query_params
|
32
|
+
if defined?(@query_params) && @query_params
|
33
33
|
URI::QueryParams.dump(@query_params)
|
34
34
|
else
|
35
35
|
raw_query
|
@@ -56,7 +56,7 @@ module URI
|
|
56
56
|
def query=(new_query)
|
57
57
|
new_query = (self.raw_query = new_query)
|
58
58
|
|
59
|
-
parse_query_params! if @query_params
|
59
|
+
parse_query_params! if defined?(@query_params) && @query_params
|
60
60
|
return new_query
|
61
61
|
end
|
62
62
|
end
|
@@ -50,10 +50,8 @@ module URI
|
|
50
50
|
next if param.empty?
|
51
51
|
|
52
52
|
name, value = param.split('=',2)
|
53
|
-
value = if value
|
54
|
-
|
55
|
-
else
|
56
|
-
''
|
53
|
+
value = if value then URI::DEFAULT_PARSER.unescape(value)
|
54
|
+
else ''
|
57
55
|
end
|
58
56
|
|
59
57
|
yield(name,value) if block_given?
|
@@ -79,14 +77,10 @@ module URI
|
|
79
77
|
#
|
80
78
|
def self.escape(value)
|
81
79
|
case value
|
82
|
-
when Array
|
83
|
-
|
84
|
-
when
|
85
|
-
|
86
|
-
when false, nil
|
87
|
-
''
|
88
|
-
else
|
89
|
-
URI::DEFAULT_PARSER.escape(value.to_s,UNSAFE)
|
80
|
+
when Array then URI::DEFAULT_PARSER.escape(value.join(' '),UNSAFE)
|
81
|
+
when true then 'active'
|
82
|
+
when false, nil then ''
|
83
|
+
else URI::DEFAULT_PARSER.escape(value.to_s,UNSAFE)
|
90
84
|
end
|
91
85
|
end
|
92
86
|
|
@@ -116,18 +110,9 @@ module URI
|
|
116
110
|
# @api semipublic
|
117
111
|
#
|
118
112
|
def self.dump(query_params)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
query_params.rehash if RUBY_VERSION < '1.9'
|
123
|
-
|
124
|
-
query_params.each do |name,value|
|
125
|
-
value = escape(value)
|
126
|
-
|
127
|
-
query << "#{name}=#{value}"
|
128
|
-
end
|
129
|
-
|
130
|
-
return query.join('&')
|
113
|
+
query_params.map { |name,value|
|
114
|
+
"#{name}=#{escape(value)}"
|
115
|
+
}.join('&')
|
131
116
|
end
|
132
117
|
|
133
118
|
end
|
data/lib/uri/query_params.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'uri/query_params/query_params'
|
2
|
-
require 'uri/query_params/
|
2
|
+
require 'uri/query_params/core_ext'
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'query_params_mixin_examples'
|
3
|
-
require 'uri/query_params/
|
3
|
+
require 'uri/query_params/core_ext/addressable/uri'
|
4
4
|
|
5
5
|
describe Addressable::URI do
|
6
|
-
|
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
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'query_params_mixin_examples'
|
3
|
+
require 'uri/query_params/core_ext/uri/http'
|
4
|
+
|
5
|
+
describe URI::HTTP do
|
6
|
+
subject { URI.parse("http://www.example.com/page.php") }
|
7
|
+
|
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
|
77
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'uri/query_params/extensions/addressable/uri'
|
3
|
+
|
4
|
+
describe 'uri/query_params/extensions/addressable/uri' do
|
5
|
+
let(:root) { File.expand_path(File.join('..','..','..'),__dir__) }
|
6
|
+
let(:path) do
|
7
|
+
File.join(root,'lib','uri','query_params','core_ext', 'addressable','uri.rb')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "must require 'uri/query_params/core_ext/addressable/uri'" do
|
11
|
+
expect($LOADED_FEATURES).to include(path)
|
12
|
+
end
|
13
|
+
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require '
|
3
|
-
require 'uri/query_params/extensions/uri'
|
2
|
+
require 'uri/query_params/extensions/uri/generic'
|
4
3
|
|
5
|
-
describe
|
6
|
-
let(:
|
4
|
+
describe 'uri/query_params/extensions/uri/generic' do
|
5
|
+
let(:root) { File.expand_path(File.join('..','..','..'),__dir__) }
|
6
|
+
let(:path) do
|
7
|
+
File.join(root,'lib','uri','query_params','core_ext', 'uri','generic.rb')
|
8
|
+
end
|
7
9
|
|
8
|
-
|
10
|
+
it "must require 'uri/query_params/core_ext/uri/generic'" do
|
11
|
+
expect($LOADED_FEATURES).to include(path)
|
12
|
+
end
|
9
13
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'uri/query_params/extensions/uri'
|
3
|
+
|
4
|
+
describe 'uri/query_params/extensions/uri' do
|
5
|
+
let(:root) { File.expand_path(File.join('..','..'),__dir__) }
|
6
|
+
let(:path) { File.join(root,'lib','uri','query_params','core_ext', 'uri.rb') }
|
7
|
+
|
8
|
+
it "must require 'uri/query_params/core_ext/uri'" do
|
9
|
+
expect($LOADED_FEATURES).to include(path)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'uri/query_params/extensions'
|
3
|
+
|
4
|
+
describe 'uri/query_params/extensions' do
|
5
|
+
let(:root) { File.expand_path('..',__dir__) }
|
6
|
+
let(:path) { File.join(root,'lib','uri','query_params','core_ext.rb') }
|
7
|
+
|
8
|
+
it "must require 'uri/query_params/core_ext'" do
|
9
|
+
expect($LOADED_FEATURES).to include(path)
|
10
|
+
end
|
11
|
+
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
|
-
|
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(
|
17
|
+
expect(subject.query).to eq(query)
|
20
18
|
end
|
21
19
|
|
22
20
|
it "should provide #query_params" do
|
23
|
-
|
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
|
-
|
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
data/uri-query_params.gemspec
CHANGED
@@ -2,126 +2,60 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
`git ls-files`.split($/)
|
8
|
-
elsif File.directory?('.hg')
|
9
|
-
`hg manifest`.split($/)
|
10
|
-
elsif File.directory?('.svn')
|
11
|
-
`svn ls -R`.split($/).select { |path| File.file?(path) }
|
12
|
-
else
|
13
|
-
Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
|
14
|
-
end
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gemspec = YAML.load_file('gemspec.yml')
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
when String
|
21
|
-
(files & Dir[paths])
|
22
|
-
end
|
23
|
-
}
|
24
|
-
|
25
|
-
version = {
|
26
|
-
:file => 'lib/uri/query_params/version.rb',
|
27
|
-
:constant => 'URI::QueryParams::VERSION'
|
28
|
-
}
|
29
|
-
|
30
|
-
defaults = {
|
31
|
-
'name' => File.basename(File.dirname(__FILE__)),
|
32
|
-
'files' => files,
|
33
|
-
'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
|
34
|
-
'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
|
35
|
-
'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
|
36
|
-
}
|
37
|
-
|
38
|
-
metadata = defaults.merge(YAML.load_file('gemspec.yml'))
|
39
|
-
|
40
|
-
gemspec.name = metadata.fetch('name',defaults[:name])
|
41
|
-
gemspec.version = if metadata['version']
|
42
|
-
metadata['version']
|
43
|
-
elsif File.file?(version[:file])
|
44
|
-
require File.join('.',version[:file])
|
45
|
-
eval(version[:constant])
|
46
|
-
end
|
47
|
-
|
48
|
-
gemspec.summary = metadata.fetch('summary',metadata['description'])
|
49
|
-
gemspec.description = metadata.fetch('description',metadata['summary'])
|
50
|
-
|
51
|
-
case metadata['license']
|
52
|
-
when Array
|
53
|
-
gemspec.licenses = metadata['license']
|
54
|
-
when String
|
55
|
-
gemspec.license = metadata['license']
|
56
|
-
end
|
57
|
-
|
58
|
-
case metadata['authors']
|
59
|
-
when Array
|
60
|
-
gemspec.authors = metadata['authors']
|
61
|
-
when String
|
62
|
-
gemspec.author = metadata['authors']
|
63
|
-
end
|
8
|
+
gem.name = gemspec.fetch('name')
|
9
|
+
gem.version = gemspec.fetch('version') do
|
10
|
+
lib_dir = File.join(File.dirname(__FILE__),'lib')
|
11
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
64
12
|
|
65
|
-
|
66
|
-
|
13
|
+
require 'uri/query_params/version'
|
14
|
+
URI::QueryParams::VERSION
|
15
|
+
end
|
67
16
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
17
|
+
gem.summary = gemspec['summary']
|
18
|
+
gem.description = gemspec['description']
|
19
|
+
gem.licenses = Array(gemspec['license'])
|
20
|
+
gem.authors = Array(gemspec['authors'])
|
21
|
+
gem.email = gemspec['email']
|
22
|
+
gem.homepage = gemspec['homepage']
|
23
|
+
gem.metadata = gemspec['metadata'] if gemspec['metadata']
|
74
24
|
|
75
|
-
|
25
|
+
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
76
26
|
|
77
|
-
|
78
|
-
|
27
|
+
gem.files = `git ls-files`.split($/)
|
28
|
+
gem.files = glob[gemspec['files']] if gemspec['files']
|
79
29
|
|
80
|
-
|
81
|
-
|
30
|
+
gem.executables = gemspec.fetch('executables') do
|
31
|
+
glob['bin/*'].map { |path| File.basename(path) }
|
82
32
|
end
|
33
|
+
gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
|
83
34
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
gemspec.extra_rdoc_files = metadata['extra_doc_files']
|
88
|
-
end
|
89
|
-
|
90
|
-
gemspec.post_install_message = metadata['post_install_message']
|
91
|
-
gemspec.requirements = metadata['requirements']
|
92
|
-
|
93
|
-
if gemspec.respond_to?(:required_ruby_version=)
|
94
|
-
gemspec.required_ruby_version = metadata['required_ruby_version']
|
95
|
-
end
|
35
|
+
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
36
|
+
gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
|
37
|
+
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
|
96
38
|
|
97
|
-
|
98
|
-
|
99
|
-
|
39
|
+
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
40
|
+
%w[ext lib].select { |dir| File.directory?(dir) }
|
41
|
+
})
|
100
42
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
when String
|
106
|
-
versions.split(/,\s*/)
|
107
|
-
end
|
108
|
-
}
|
43
|
+
gem.requirements = gemspec['requirements']
|
44
|
+
gem.required_ruby_version = gemspec['required_ruby_version']
|
45
|
+
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
46
|
+
gem.post_install_message = gemspec['post_install_message']
|
109
47
|
|
110
|
-
|
111
|
-
metadata['dependencies'].each do |name,versions|
|
112
|
-
gemspec.add_dependency(name,parse_versions[versions])
|
113
|
-
end
|
114
|
-
end
|
48
|
+
split = lambda { |string| string.split(/,\s*/) }
|
115
49
|
|
116
|
-
if
|
117
|
-
|
118
|
-
|
50
|
+
if gemspec['dependencies']
|
51
|
+
gemspec['dependencies'].each do |name,versions|
|
52
|
+
gem.add_dependency(name,split[versions])
|
119
53
|
end
|
120
54
|
end
|
121
55
|
|
122
|
-
if
|
123
|
-
|
124
|
-
|
56
|
+
if gemspec['development_dependencies']
|
57
|
+
gemspec['development_dependencies'].each do |name,versions|
|
58
|
+
gem.add_development_dependency(name,split[versions])
|
125
59
|
end
|
126
60
|
end
|
127
61
|
end
|
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.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,7 +28,10 @@ description: Allows access to the query component of the URI as a Hash.
|
|
28
28
|
email: postmodern.mod3@gmail.com
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
31
|
-
extra_rdoc_files:
|
31
|
+
extra_rdoc_files:
|
32
|
+
- ChangeLog.md
|
33
|
+
- LICENSE.txt
|
34
|
+
- README.md
|
32
35
|
files:
|
33
36
|
- ".document"
|
34
37
|
- ".github/workflows/ruby.yml"
|
@@ -42,6 +45,11 @@ files:
|
|
42
45
|
- Rakefile
|
43
46
|
- gemspec.yml
|
44
47
|
- lib/uri/query_params.rb
|
48
|
+
- lib/uri/query_params/core_ext.rb
|
49
|
+
- lib/uri/query_params/core_ext/addressable/uri.rb
|
50
|
+
- lib/uri/query_params/core_ext/uri.rb
|
51
|
+
- lib/uri/query_params/core_ext/uri/generic.rb
|
52
|
+
- lib/uri/query_params/core_ext/uri/http.rb
|
45
53
|
- lib/uri/query_params/extensions.rb
|
46
54
|
- lib/uri/query_params/extensions/addressable/uri.rb
|
47
55
|
- lib/uri/query_params/extensions/uri.rb
|
@@ -49,9 +57,13 @@ files:
|
|
49
57
|
- lib/uri/query_params/mixin.rb
|
50
58
|
- lib/uri/query_params/query_params.rb
|
51
59
|
- lib/uri/query_params/version.rb
|
52
|
-
- spec/
|
60
|
+
- spec/core_ext/addressable/uri_spec.rb
|
61
|
+
- spec/core_ext/uri/generic_spec.rb
|
62
|
+
- spec/core_ext/uri/http_spec.rb
|
63
|
+
- spec/extensions/addressable/uri.rb
|
53
64
|
- spec/extensions/uri/generic_spec.rb
|
54
|
-
- spec/extensions/
|
65
|
+
- spec/extensions/uri_spec.rb
|
66
|
+
- spec/extensions_spec.rb
|
55
67
|
- spec/query_params_mixin_examples.rb
|
56
68
|
- spec/query_params_spec.rb
|
57
69
|
- spec/spec_helper.rb
|
@@ -59,8 +71,13 @@ files:
|
|
59
71
|
homepage: https://github.com/postmodern/uri-query_params
|
60
72
|
licenses:
|
61
73
|
- MIT
|
62
|
-
metadata:
|
63
|
-
|
74
|
+
metadata:
|
75
|
+
documentation_uri: https://rubydoc.info/gems/uri-query_params
|
76
|
+
source_code_uri: https://github.com/postmodern/uri-query_params.rb
|
77
|
+
bug_tracker_uri: https://github.com/postmodern/uri-query_params.rb/issues
|
78
|
+
changelog_uri: https://github.com/postmodern/uri-query_params.rb/blob/master/ChangeLog.md
|
79
|
+
rubygems_mfa_required: 'true'
|
80
|
+
post_install_message:
|
64
81
|
rdoc_options: []
|
65
82
|
require_paths:
|
66
83
|
- lib
|
@@ -68,19 +85,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
85
|
requirements:
|
69
86
|
- - ">="
|
70
87
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
88
|
+
version: 2.0.0
|
72
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
90
|
requirements:
|
74
91
|
- - ">="
|
75
92
|
- !ruby/object:Gem::Version
|
76
93
|
version: '0'
|
77
94
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
-
signing_key:
|
95
|
+
rubygems_version: 3.3.7
|
96
|
+
signing_key:
|
80
97
|
specification_version: 4
|
81
98
|
summary: Access the query parameters of a URI, just like $_GET in PHP.
|
82
|
-
test_files:
|
83
|
-
- spec/extensions/addressable/uri_spec.rb
|
84
|
-
- spec/extensions/uri/generic_spec.rb
|
85
|
-
- spec/extensions/uri/http_spec.rb
|
86
|
-
- spec/query_params_spec.rb
|
99
|
+
test_files: []
|