In Files

Parent

Class Index [+]

Quicksearch

Object

Public Instance Methods

build_nested_query(value, prefix = nil) click to toggle source

(Not documented)

     # File lib/rack/utils.rb, line 117
117:     def build_nested_query(value, prefix = nil)
118:       case value
119:       when Array
120:         value.map { |v|
121:           build_nested_query(v, "#{prefix}[]")
122:         }.join("&")
123:       when Hash
124:         value.map { |k, v|
125:           build_nested_query(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k))
126:         }.join("&")
127:       when String
128:         raise ArgumentError, "value must be a Hash" if prefix.nil?
129:         "#{prefix}=#{escape(value)}"
130:       else
131:         prefix
132:       end
133:     end
build_query(params) click to toggle source

(Not documented)

     # File lib/rack/utils.rb, line 106
106:     def build_query(params)
107:       params.map { |k, v|
108:         if v.class == Array
109:           build_query(v.map { |x| [k, x] })
110:         else
111:           "#{escape(k)}=#{escape(v)}"
112:         end
113:       }.join("&")
114:     end
bytesize(string) click to toggle source

(Not documented)

     # File lib/rack/utils.rb, line 227
227:       def bytesize(string)
228:         string.bytesize
229:       end
bytesize(string) click to toggle source

(Not documented)

     # File lib/rack/utils.rb, line 231
231:       def bytesize(string)
232:         string.size
233:       end
escape_html(string) click to toggle source

Escape ampersands, brackets and quotes to their HTML/XML entities.

     # File lib/rack/utils.rb, line 137
137:     def escape_html(string)
138:       string.to_s.gsub("&", "&").
139:         gsub("<", "&lt;").
140:         gsub(">", "&gt;").
141:         gsub("'", "&#39;").
142:         gsub('"', "&quot;")
143:     end
normalize_params(params, name, v = nil) click to toggle source

(Not documented)

     # File lib/rack/utils.rb, line 71
 71:     def normalize_params(params, name, v = nil)
 72:       if v and v =~ /^("|')(.*)\1$/
 73:         v = $2.gsub('\\'+$1, $1)
 74:       end
 75:       name =~ %r(\A[\[\]]*([^\[\]]+)\]*)
 76:       k = $1 || ''
 77:       after = $' || ''
 78: 
 79:       return if k.empty?
 80: 
 81:       if after == ""
 82:         params[k] = v
 83:       elsif after == "[]"
 84:         params[k] ||= []
 85:         raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
 86:         params[k] << v
 87:       elsif after =~ %r(^\[\]\[([^\[\]]+)\]$) || after =~ %r(^\[\](.+)$)
 88:         child_key = $1
 89:         params[k] ||= []
 90:         raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
 91:         if params[k].last.is_a?(Hash) && !params[k].last.key?(child_key)
 92:           normalize_params(params[k].last, child_key, v)
 93:         else
 94:           params[k] << normalize_params({}, child_key, v)
 95:         end
 96:       else
 97:         params[k] ||= {}
 98:         raise TypeError, "expected Hash (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Hash)
 99:         params[k] = normalize_params(params[k], after, v)
100:       end
101: 
102:       return params
103:     end
select_best_encoding(available_encodings, accept_encoding) click to toggle source

(Not documented)

     # File lib/rack/utils.rb, line 146
146:     def select_best_encoding(available_encodings, accept_encoding)
147:       # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
148: 
149:       expanded_accept_encoding =
150:         accept_encoding.map { |m, q|
151:           if m == "*"
152:             (available_encodings - accept_encoding.map { |m2, _| m2 }).map { |m2| [m2, q] }
153:           else
154:             [[m, q]]
155:           end
156:         }.inject([]) { |mem, list|
157:           mem + list
158:         }
159: 
160:       encoding_candidates = expanded_accept_encoding.sort_by { |_, q| -q }.map { |m, _| m }
161: 
162:       unless encoding_candidates.include?("identity")
163:         encoding_candidates.push("identity")
164:       end
165: 
166:       expanded_accept_encoding.find_all { |m, q|
167:         q == 0.0
168:       }.each { |m, _|
169:         encoding_candidates.delete(m)
170:       }
171: 
172:       return (encoding_candidates & available_encodings)[0]
173:     end
status_code(status) click to toggle source

(Not documented)

     # File lib/rack/utils.rb, line 402
402:     def status_code(status)
403:       if status.is_a?(Symbol)
404:         SYMBOL_TO_STATUS_CODE[status] || 500
405:       else
406:         status.to_i
407:       end
408:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.