Module: CGI::QueryExtension
- Defined in:
- lib/cgi.rb
Overview
Mixin module. It provides the follow functionality groups:
-
Access to CGI environment variables as methods. See documentation to the CGI class for a list of these variables.
-
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 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
-
#cookies ⇒ Object
Get the cookies as a hash of cookie-name=>Cookie pairs.
-
#params ⇒ Object
Get the parameters as a hash of name=>values pairs, where values is an Array.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get the value for the parameter with a given key.
-
#has_key?(*args) ⇒ Boolean
(also: #key?, #include?)
Returns true if a given parameter key exists in the query.
-
#keys(*args) ⇒ Object
Return all parameter keys as an array.
- #multipart? ⇒ Boolean
-
#raw_cookie ⇒ Object
Get the raw cookies as a string.
-
#raw_cookie2 ⇒ Object
Get the raw RFC2965 cookies as a string.
Instance Attribute Details
#cookies ⇒ Object
Get the cookies as a hash of cookie-name=>Cookie pairs.
957 958 959 |
# File 'lib/cgi.rb', line 957 def @cookies end |
#params ⇒ Object
Get the parameters as a hash of name=>values pairs, where values is an Array.
961 962 963 |
# File 'lib/cgi.rb', line 961 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.
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 |
# File 'lib/cgi.rb', line 1165 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.
1191 1192 1193 |
# File 'lib/cgi.rb', line 1191 def has_key?(*args) @params.has_key?(*args) end |
#keys(*args) ⇒ Object
Return all parameter keys as an array.
1186 1187 1188 |
# File 'lib/cgi.rb', line 1186 def keys(*args) @params.keys(*args) end |
#multipart? ⇒ Boolean
1134 1135 1136 |
# File 'lib/cgi.rb', line 1134 def multipart? @multipart end |
#raw_cookie ⇒ Object
Get the raw cookies as a string.
947 948 949 |
# File 'lib/cgi.rb', line 947 def env_table["HTTP_COOKIE"] end |
#raw_cookie2 ⇒ Object
Get the raw RFC2965 cookies as a string.
952 953 954 |
# File 'lib/cgi.rb', line 952 def env_table["HTTP_COOKIE2"] end |