Module: CGI::QueryExtension

Defined in:
lib/rubysl/cgi/cgi.rb

Overview

Mixin module. It provides the follow functionality groups:

  1. Access to CGI environment variables as methods. See documentation to the CGI class for a list of these variables.

  2. Access to cookies, including the cookies attribute.

  3. Access to parameters, including the params attribute, and overloading

    to perform parameter value lookup by key.

  4. The initialize_query method, for initialising the above mechanisms, handling multipart forms, and allowing the class to be used in “offline” mode.

Defined Under Namespace

Modules: Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cookiesObject

Get the cookies as a hash of cookie-name=>Cookie pairs.



970
971
972
# File 'lib/rubysl/cgi/cgi.rb', line 970

def cookies
  @cookies
end

#paramsObject

Get the parameters as a hash of name=>values pairs, where values is an Array.



974
975
976
# File 'lib/rubysl/cgi/cgi.rb', line 974

def params
  @params
end

Instance Method Details

#[](key) ⇒ Object

Get the value for the parameter with a given key.

If the parameter has multiple values, only the first will be retrieved; use #params() to get the array of values.



1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
# File 'lib/rubysl/cgi/cgi.rb', line 1178

def [](key)
  params = @params[key]
  return '' unless params
  value = params[0]
  if @multipart
    if value
      return value
    elsif defined? StringIO
      StringIO.new("")
    else
      Tempfile.new("CGI")
    end
  else
    str = if value then value.dup else "" end
    str.extend(Value)
    str.set_params(params)
    str
  end
end

#has_key?(*args) ⇒ Boolean Also known as: key?, include?

Returns true if a given parameter key exists in the query.



1204
1205
1206
# File 'lib/rubysl/cgi/cgi.rb', line 1204

def has_key?(*args)
  @params.has_key?(*args)
end

#keys(*args) ⇒ Object

Return all parameter keys as an array.



1199
1200
1201
# File 'lib/rubysl/cgi/cgi.rb', line 1199

def keys(*args)
  @params.keys(*args)
end

#multipart?Boolean



1147
1148
1149
# File 'lib/rubysl/cgi/cgi.rb', line 1147

def multipart?
  @multipart
end

Get the raw cookies as a string.



960
961
962
# File 'lib/rubysl/cgi/cgi.rb', line 960

def raw_cookie
  env_table["HTTP_COOKIE"]
end

#raw_cookie2Object

Get the raw RFC2965 cookies as a string.



965
966
967
# File 'lib/rubysl/cgi/cgi.rb', line 965

def raw_cookie2
  env_table["HTTP_COOKIE2"]
end