queryparams 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/queryparams.rb +5 -10
- data/lib/queryparams/version.rb +1 -1
- data/spec/queryparams_spec.rb +2 -2
- metadata +4 -4
data/README.md
CHANGED
data/lib/queryparams.rb
CHANGED
@@ -4,18 +4,13 @@ require "cgi"
|
|
4
4
|
module QueryParams
|
5
5
|
|
6
6
|
def self.encode(value, key = nil)
|
7
|
-
q = []
|
8
7
|
case value
|
9
|
-
when Hash
|
10
|
-
|
11
|
-
when
|
12
|
-
|
13
|
-
|
14
|
-
return ''
|
15
|
-
else
|
16
|
-
return "#{key}=#{CGI.escape(value.to_s)}"
|
8
|
+
when Hash then value.map { |k,v| encode(v, append_key(key,k)) }.join('&')
|
9
|
+
when Array then value.map { |v| encode(v, "#{key}[]") }.join('&')
|
10
|
+
when nil then ''
|
11
|
+
else
|
12
|
+
"#{key}=#{CGI.escape(value.to_s)}"
|
17
13
|
end
|
18
|
-
q.join('&')
|
19
14
|
end
|
20
15
|
|
21
16
|
private
|
data/lib/queryparams/version.rb
CHANGED
data/spec/queryparams_spec.rb
CHANGED
@@ -16,10 +16,10 @@ describe QueryParams do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "handles arrays" do
|
19
|
-
QueryParams.encode({a: ['bingo', 'hepp']}).should eq "a[
|
19
|
+
QueryParams.encode({a: ['bingo', 'hepp']}).should eq "a[]=bingo&a[]=hepp"
|
20
20
|
end
|
21
21
|
|
22
22
|
it "handles arrays of hashes" do
|
23
|
-
QueryParams.encode({a: [{b:'c', d:'e'}, {f:'g'}]}).should eq "a[
|
23
|
+
QueryParams.encode({a: [{b:'c', d:'e'}, {f:'g'}]}).should eq "a[][b]=c&a[][d]=e&a[][f]=g"
|
24
24
|
end
|
25
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queryparams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-31 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70281918100620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70281918100620
|
25
25
|
description: ! ' It supports hashes, arrays, nested hashes and arrays of hashes and
|
26
26
|
all combinations thereof.'
|
27
27
|
email:
|