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 :
M000001.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>normalize_params (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 129</span> <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">normalize_params</span>(<span class="ruby-identifier">params</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">v</span> = <span class="ruby-keyword kw">nil</span>) <span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">%r(\A[\[\]]*([^\[\]]+)\]*)</span> <span class="ruby-identifier">k</span> = <span class="ruby-identifier">$1</span> <span class="ruby-operator">||</span> <span class="ruby-value str">''</span> <span class="ruby-identifier">after</span> = <span class="ruby-identifier">$'</span> <span class="ruby-operator">||</span> <span class="ruby-value str">''</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">after</span> <span class="ruby-operator">==</span> <span class="ruby-value str">""</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span> <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">after</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"["</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">v</span> <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">after</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"[]"</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">||=</span> [] <span class="ruby-identifier">raise</span> <span class="ruby-constant">ParameterTypeError</span>, <span class="ruby-node">"expected Array (got #{params[k].class.name}) for param `#{k}'"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">v</span> <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">after</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">%r(^\[\]\[([^\[\]]+)\]$)</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">after</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">%r(^\[\](.+)$)</span> <span class="ruby-identifier">child_key</span> = <span class="ruby-identifier">$1</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">||=</span> [] <span class="ruby-identifier">raise</span> <span class="ruby-constant">ParameterTypeError</span>, <span class="ruby-node">"expected Array (got #{params[k].class.name}) for param `#{k}'"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params_hash_type?</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">last</span>) <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">last</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">child_key</span>) <span class="ruby-identifier">normalize_params</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>].<span class="ruby-identifier">last</span>, <span class="ruby-identifier">child_key</span>, <span class="ruby-identifier">v</span>) <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">normalize_params</span>(<span class="ruby-identifier">params</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>, <span class="ruby-identifier">child_key</span>, <span class="ruby-identifier">v</span>) <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">params</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">ParameterTypeError</span>, <span class="ruby-node">"expected Hash (got #{params[k].class.name}) for param `#{k}'"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">params_hash_type?</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>]) <span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">normalize_params</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">k</span>], <span class="ruby-identifier">after</span>, <span class="ruby-identifier">v</span>) <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">params</span> <span class="ruby-keyword kw">end</span></pre> </body> </html>