module CGI::QueryExtension
Mixin module that provides the following:
-
Access to the
CGI
environment variables as methods. See documentation to theCGI
class for a list of these variables. The methods are exposed by removing the leadingHTTP_
(if it exists) and downcasing the name. For example,auth_type
will return the environment variableAUTH_TYPE
, andaccept
will return the value forHTTP_ACCEPT
. -
Access to cookies, including the cookies attribute.
-
Access to parameters, including the params attribute, and overloading
[]
to perform parameter value lookup by key. -
The initialize_query method, for initializing the above mechanisms, handling multipart forms, and allowing the class to be used in “offline” mode.
Attributes
Get the uploaded files as a hash of name=>values pairs
Get the parameters as a hash of name=>values pairs, where values is an Array
.
Public Instance Methods
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.
# File lib/cgi/core.rb, line 714 def [](key) params = @params[key] return '' unless params value = params[0] if @multipart if value return value elsif defined? StringIO StringIO.new("".b) else Tempfile.new("CGI",encoding: Encoding::ASCII_8BIT) end else str = if value then value.dup else "" end str end end
Returns true if a given query string parameter exists.
# File lib/cgi/core.rb, line 738 def has_key?(*args) @params.has_key?(*args) end
Return all query parameter names as an array of String
.
# File lib/cgi/core.rb, line 733 def keys(*args) @params.keys(*args) end
Returns whether the form contained multipart/form-data
# File lib/cgi/core.rb, line 706 def multipart? @multipart end
Set
all the parameters.
# File lib/cgi/core.rb, line 474 def params=(hash) @params.clear @params.update(hash) end