rack-jquery-params 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rack/jquery-params/load.rb +12 -13
- data/lib/rack/jquery-params/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18389012615ac37ddcf3655ef105a4cb7a41a02e
|
4
|
+
data.tar.gz: 38b8a88405e234cf388ed6fcf6968b0933a0e135
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8486aceb8fc6a32793a62232bdb7c7955393efa8ca66ea2e07bd239cc86b3e5a33318921e0e25e1eeb45c8cf8e194bffb1b5bcc5948cbddb6954ef1cfbb7082f
|
7
|
+
data.tar.gz: 58e006ec024afea9ad55f6ed97212b064af05b9ff275d4cca550b941bd4eff5b4d42e2b91b7e1f0d68d09eced5f9f667a12376f1845a72062ff0500f317afd1e
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rack'
|
2
2
|
|
3
|
+
# Loops through all params and convert the hashes to arrays only if all keys are comprised of integers.
|
3
4
|
module Rack
|
4
5
|
class JQueryParams
|
5
6
|
include Rack::Utils
|
@@ -12,8 +13,6 @@ module Rack
|
|
12
13
|
@app = app
|
13
14
|
end
|
14
15
|
|
15
|
-
# Loops through all params and convert the hashes to arrays only if all keys are comprised of integers.
|
16
|
-
#
|
17
16
|
def call(env)
|
18
17
|
status, headers, response = @app.call(env)
|
19
18
|
|
@@ -24,22 +23,22 @@ module Rack
|
|
24
23
|
def self.fix(env, valid_methods=:all)
|
25
24
|
valid_methods = extract_valid_methods(valid_methods)
|
26
25
|
return if valid_methods != :all and !valid_methods.include?(env['REQUEST_METHOD'])
|
27
|
-
|
28
|
-
|
26
|
+
fix_params(env['rack.request.query_hash'])
|
27
|
+
fix_params(env['rack.request.form_hash'])
|
29
28
|
end
|
30
29
|
|
31
|
-
def self.
|
32
|
-
if
|
33
|
-
if
|
34
|
-
|
30
|
+
def self.fix_params(params)
|
31
|
+
if params.is_a?(Hash)
|
32
|
+
if params.all?{|k,v| k =~ /^[0-9]+$/}
|
33
|
+
params.sort.inject([]){|result, v| result << fix_params(v[1]) }
|
35
34
|
else
|
36
|
-
|
35
|
+
params.each{|k,v| params[k] = fix_params(v) }
|
37
36
|
end
|
38
|
-
elsif
|
39
|
-
|
40
|
-
return
|
37
|
+
elsif params.is_a?(Array)
|
38
|
+
params.each_with_index {|v,i| params[i] = fix_params(v) }
|
39
|
+
return params
|
41
40
|
else
|
42
|
-
return
|
41
|
+
return params
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|