cgi-query_string 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/cgi-query_string.gemspec +28 -0
- data/lib/cgi/query_string.rb +65 -0
- data/lib/cgi/query_string/version.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 20e4448fb2fd7fbdf95e994fffdf7b0d0312899c
|
4
|
+
data.tar.gz: 228847e668eeb77e1b00d66e619f78527be5eaad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 208915c477bceb91f18ac375819ffbd0bf6ef751471f790b282ce3a9c6a73bf61804d7a7ddd857ba4a862b04252c12e4a9611972f134482899969a9a0fbfe0ec
|
7
|
+
data.tar.gz: 2081dbb301e3ca133fc3df6a2113b5d383875a4db3c1d3de6acb6e0a8c9065780fc0f0d166f695e462eefce43f584cf7e1f4abd66d9fb85f7a29b3126ce60f1c
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Butch Marshall
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# CGI::QueryString
|
2
|
+
|
3
|
+
Helper methods for dealing with query strings in ruby.
|
4
|
+
|
5
|
+
Basically trying to replicate ActiveSupports [to_query ](http://guides.rubyonrails.org/v3.2.21/active_support_core_extensions.html#to_query) method without having to include all of ActiveSupport.
|
6
|
+
|
7
|
+
Hopefully someone finds this useful.
|
8
|
+
|
9
|
+
TODO: add a deparam method
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'cgi-query_string'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install cgi-query_string
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'cgi/query_string'
|
31
|
+
|
32
|
+
CGI::QueryString.param({
|
33
|
+
:a => 1,
|
34
|
+
:b => {
|
35
|
+
:c => [1,2,3]
|
36
|
+
},
|
37
|
+
:d => [4,5,6]
|
38
|
+
})
|
39
|
+
|
40
|
+
== "a=1&b%5Bc%5D%5B%5D=1&b%5Bc%5D%5B%5D=2&b%5Bc%5D%5B%5D=3&d%5B%5D=4&d%5B%5D=5&d%5B%5D=6"
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/butchmarshall/ruby-cgi-query_string.
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
51
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cgi/query_string"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cgi/query_string'
|
5
|
+
require 'cgi/query_string/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "cgi-query_string"
|
9
|
+
spec.version = CGI::QueryString::VERSION
|
10
|
+
spec.authors = ["Butch Marshall"]
|
11
|
+
spec.email = ["butch.a.marshall@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Helper methods for dealing with query strings in ruby.}
|
14
|
+
spec.description = %q{Basically trying to replicate ActiveSupports to_query method without having to include all of ActiveSupport.
|
15
|
+
|
16
|
+
Hopefully someone finds this useful.}
|
17
|
+
spec.homepage = "https://github.com/butchmarshall/ruby-cgi-query_string"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency 'rspec', '~> 0'
|
28
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'cgi/query_string/version'
|
3
|
+
|
4
|
+
module CGI::QueryString #:nodoc:
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# Serialize an array into a query string
|
8
|
+
#
|
9
|
+
# Ruby version of jQuerys param method
|
10
|
+
#
|
11
|
+
# * *Args* :
|
12
|
+
# - +hash+ -> Hash to serialize
|
13
|
+
# * *Returns* :
|
14
|
+
# - a query string
|
15
|
+
#
|
16
|
+
def param(a)
|
17
|
+
s = []
|
18
|
+
add = lambda { |k,v|
|
19
|
+
s << "#{::CGI.escape(k.to_s)}=#{::CGI.escape(v.to_s)}"
|
20
|
+
}
|
21
|
+
|
22
|
+
if a.is_a?(Array)
|
23
|
+
a.each { |v,i|
|
24
|
+
self.build_params("", v)
|
25
|
+
}
|
26
|
+
elsif a.is_a?(Hash)
|
27
|
+
a.each_pair { |prefix,v|
|
28
|
+
build_params(prefix, v, add)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
s.join("&").gsub(/%20/, "+")
|
33
|
+
end
|
34
|
+
|
35
|
+
# Builds params
|
36
|
+
#
|
37
|
+
# Helper function
|
38
|
+
#
|
39
|
+
# * *Args* :
|
40
|
+
# - +string+ -> Hash to serialize
|
41
|
+
# - +Hash+ -> Hash to serialize
|
42
|
+
# - +lambda+ -> Hash to serialize
|
43
|
+
# * *Returns* :
|
44
|
+
# - false
|
45
|
+
#
|
46
|
+
def build_params(prefix, obj, add)
|
47
|
+
if obj.is_a?(Array)
|
48
|
+
obj.each { |v, i|
|
49
|
+
if !(/\[\]$/.match(prefix).nil?)
|
50
|
+
add.call(prefix, v)
|
51
|
+
else
|
52
|
+
build_params("#{prefix}[#{ ((v.is_a?(Array) || v.is_a?(Hash)) ? i : "") }]", v, add)
|
53
|
+
end
|
54
|
+
}
|
55
|
+
elsif obj.is_a?(Hash)
|
56
|
+
obj.each_pair { |name,o|
|
57
|
+
build_params("#{prefix}[#{name}]", o, add)
|
58
|
+
}
|
59
|
+
else
|
60
|
+
add.call(prefix, obj)
|
61
|
+
end
|
62
|
+
|
63
|
+
true
|
64
|
+
end
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cgi-query_string
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Butch Marshall
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |-
|
56
|
+
Basically trying to replicate ActiveSupports to_query method without having to include all of ActiveSupport.
|
57
|
+
|
58
|
+
Hopefully someone finds this useful.
|
59
|
+
email:
|
60
|
+
- butch.a.marshall@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- cgi-query_string.gemspec
|
72
|
+
- lib/cgi/query_string.rb
|
73
|
+
- lib/cgi/query_string/version.rb
|
74
|
+
homepage: https://github.com/butchmarshall/ruby-cgi-query_string
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.4.8
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Helper methods for dealing with query strings in ruby.
|
98
|
+
test_files: []
|