Class Index [+]

Quicksearch

Rack::Utils

Rack::Utils contains a grab-bag of useful methods for writing web applications adopted from all kinds of Ruby libraries.

Constants

DEFAULT_SEP
(Not documented)

Public Class Methods

escape(s) click to toggle source

Performs URI escaping so that you can construct proper query strings faster. Use this rather than the cgi.rb version since it’s faster. (Stolen from Camping).

    # File lib/rack/utils.rb, line 14
14:     def escape(s)
15:       s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
16:         '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
17:       }.tr(' ', '+')
18:     end
unescape(s) click to toggle source

Unescapes a URI escaped string. (Stolen from Camping).

    # File lib/rack/utils.rb, line 22
22:     def unescape(s)
23:       s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){
24:         [$1.delete('%')].pack('H*')
25:       }
26:     end

Public Instance Methods

parse_query(qs, d = nil) click to toggle source

Stolen from Mongrel, with some small modifications: Parses a query string by breaking it up at the ’&’ and ’;’ characters. You can also use this to parse cookies by changing the characters used in the second parameter (which defaults to ’&;’).

    # File lib/rack/utils.rb, line 36
36:     def parse_query(qs, d = nil)
37:       params = {}
38: 
39:       (qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
40:         k, v = p.split('=', 2).map { |x| unescape(x) }
41:         if v =~ /^("|')(.*)\1$/
42:           v = $2.gsub('\\'+$1, $1)
43:         end
44:         if cur = params[k]
45:           if cur.class == Array
46:             params[k] << v
47:           else
48:             params[k] = [cur, v]
49:           end
50:         else
51:           params[k] = v
52:         end
53:       end

Private Instance Methods

escape(s) click to toggle source

Performs URI escaping so that you can construct proper query strings faster. Use this rather than the cgi.rb version since it’s faster. (Stolen from Camping).

    # File lib/rack/utils.rb, line 14
14:     def escape(s)
15:       s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
16:         '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
17:       }.tr(' ', '+')
18:     end
unescape(s) click to toggle source

Unescapes a URI escaped string. (Stolen from Camping).

    # File lib/rack/utils.rb, line 22
22:     def unescape(s)
23:       s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){
24:         [$1.delete('%')].pack('H*')
25:       }
26:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.