D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby18
/
lib64
/
ruby
/
gems
/
1.8
/
doc
/
rack-1.6.1
/
rdoc
/
files
/
lib
/
rack
/
utils_rb.src
/
Filename :
M000004.html
back
Copy
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>build_nested_query (lib/rack/utils.rb)</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" /> </head> <body class="standalone-code"> <pre><span class="ruby-comment cmt"># File lib/rack/utils.rb, line 179</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">build_nested_query</span>(<span class="ruby-identifier">value</span>, <span class="ruby-identifier">prefix</span> = <span class="ruby-keyword kw">nil</span>) <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">value</span> <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">build_nested_query</span>(<span class="ruby-identifier">v</span>, <span class="ruby-node">"#{prefix}[]"</span>) }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">"&"</span>) <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">build_nested_query</span>(<span class="ruby-identifier">v</span>, <span class="ruby-identifier">prefix</span> <span class="ruby-value">? </span><span class="ruby-node">"#{prefix}[#{escape(k)}]"</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">k</span>)) }.<span class="ruby-identifier">reject</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">:empty?</span>).<span class="ruby-identifier">join</span>(<span class="ruby-value str">'&'</span>) <span class="ruby-keyword kw">when</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-identifier">prefix</span> <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"value must be a Hash"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">prefix</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-node">"#{prefix}=#{escape(value)}"</span> <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">end</span></pre> </body> </html>