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 CHANGED
@@ -12,4 +12,4 @@ A straight forward gem to convert ruby hashes and arrays to http query strings.
12
12
  => "a[0]=bingo&a[1]=hepp"
13
13
 
14
14
  QueryParams.encode({a: [{b:'c', d:'e'}, {f:'g'}]})
15
- => "a[0][b]=c&a[0][d]=e&a[1][f]=g"
15
+ => "a[][b]=c&a[][d]=e&a[][f]=g"
@@ -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
- value.each { |k,v| q << encode(v, append_key(key,k)) }
11
- when Array
12
- value.each_with_index { |v,i| q << encode(v, append_key(key, i)) }
13
- when nil
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
@@ -1,3 +1,3 @@
1
1
  module QueryParams
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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[0]=bingo&a[1]=hepp"
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[0][b]=c&a[0][d]=e&a[1][f]=g"
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.2
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-29 00:00:00.000000000Z
12
+ date: 2011-10-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70151522636860 !ruby/object:Gem::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: *70151522636860
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: