Returns true
if the queue is empty.
Removes all objects from the queue.
Retrieves data from the queue.
If the queue is empty, the calling thread is suspended until data is pushed onto the queue. If non_block
is true, the thread isn’t suspended, and ThreadError
is raised.
If timeout
seconds have passed and no data is available nil
is returned. If timeout
is 0
it returns immediately.
Returns true
if key
is a key in self
, otherwise false
.
Removes all map entries; returns self
.
Returns URL-escaped string following RFC 3986.
Returns URL-unescaped string following RFC 3986.
URL-encode a string following RFC 3986 Space characters (+“ ”+) are encoded with (+“%20”+)
url_encoded_string = CGI.escapeURIComponent("'Stop!' said Fred") # => "%27Stop%21%27%20said%20Fred"
URL-decode a string following RFC 3986 with encoding(optional).
string = CGI.unescapeURIComponent("%27Stop%21%27+said%20Fred") # => "'Stop!'+said Fred"
Resets the digest to the initial state and returns self.
This method is overridden by each implementation subclass.
If none is given, returns the resulting hash value of the digest in a base64 encoded form, keeping the digest’s state.
If a string
is given, returns the hash value for the given string
in a base64 encoded form, resetting the digest to the initial state before and after the process.
In either case, the return value is properly padded with ‘=’ and contains no line feeds.
Returns the resulting hash value and resets the digest to the initial state.
Reads a one-character string from the stream. Raises an EOFError
at end of file.
Closes the SSLSocket and flushes any unwritten data.
Derives a key from pass using given parameters with the scrypt password-based key derivation function. The result can be used for password storage.
scrypt is designed to be memory-hard and more secure against brute-force attacks using custom hardwares than alternative KDFs such as PBKDF2 or bcrypt.
The keyword arguments N, r and p can be used to tune scrypt. RFC 7914 (published on 2016-08, www.rfc-editor.org/rfc/rfc7914#section-2) states that using values r=8 and p=1 appears to yield good results.
See RFC 7914 (www.rfc-editor.org/rfc/rfc7914) for more information.
Passphrase.
Salt.
CPU/memory cost parameter. This must be a power of 2.
Block size parameter.
Parallelization parameter.
Length in octets of the derived key.
pass = "password" salt = SecureRandom.random_bytes(16) dk = OpenSSL::KDF.scrypt(pass, salt: salt, N: 2**14, r: 8, p: 1, length: 32) p dk #=> "\xDA\xE4\xE2...\x7F\xA1\x01T"
::seed
is equivalent to ::add where entropy is length of str.
Start streaming using encoding
Generate a Document Base URI
element as a String
.
href
can either by a string, giving the base URL for the HREF attribute, or it can be a has of the element’s attributes.
The passed-in no-argument block is ignored.
base("http://www.example.com/cgi") # => "<BASE HREF=\"http://www.example.com/cgi\">"
Generate a reset button Input element, as a String
.
This resets the values on a form to their initial values. value
is the text displayed on the button. name
is the name of this button.
Alternatively, the attributes can be specified as a hash.
reset # <INPUT TYPE="reset"> reset("reset") # <INPUT TYPE="reset" VALUE="reset"> reset("VALUE" => "reset", "ID" => "foo") # <INPUT TYPE="reset" VALUE="reset" ID="foo">
Generate a TextArea element, as a String
.
name
is the name of the textarea. cols
is the number of columns and rows
is the number of rows in the display.
Alternatively, the attributes can be specified as a hash.
The body is provided by the passed-in no-argument block
textarea("name") # = textarea("NAME" => "name", "COLS" => 70, "ROWS" => 10) textarea("name", 40, 5) # = textarea("NAME" => "name", "COLS" => 40, "ROWS" => 5)
OpenURI::OpenRead#open
provides ‘open’ for URI::HTTP
and URI::FTP
.
OpenURI::OpenRead#open
takes optional 3 arguments as:
OpenURI::OpenRead#open([mode [, perm]] [, options]) [{|io| ... }]
OpenURI::OpenRead#open
returns an IO-like object if block is not given. Otherwise it yields the IO
object and return the value of the block. The IO
object is extended with OpenURI::Meta
.
mode
and perm
are the same as Kernel#open
.
However, mode
must be read mode because OpenURI::OpenRead#open
doesn’t support write mode (yet). Also perm
is ignored because it is meaningful only for file creation.
options
must be a hash.
Each option with a string key specifies an extra header field for HTTP. I.e., it is ignored for FTP without HTTP proxy.
The hash may include other options, where keys are symbols:
Synopsis:
:proxy => "http://proxy.foo.com:8000/" :proxy => URI.parse("http://proxy.foo.com:8000/") :proxy => true :proxy => false :proxy => nil
If :proxy option is specified, the value should be String
, URI
, boolean or nil.
When String
or URI
is given, it is treated as proxy URI
.
When true is given or the option itself is not specified, environment variable ‘scheme_proxy’ is examined. ‘scheme’ is replaced by ‘http’, ‘https’ or ‘ftp’.
When false or nil is given, the environment variables are ignored and connection will be made to a server directly.
Synopsis:
:proxy_http_basic_authentication => ["http://proxy.foo.com:8000/", "proxy-user", "proxy-password"] :proxy_http_basic_authentication => [URI.parse("http://proxy.foo.com:8000/"), "proxy-user", "proxy-password"]
If :proxy option is specified, the value should be an Array
with 3 elements. It should contain a proxy URI
, a proxy user name and a proxy password. The proxy URI
should be a String
, an URI
or nil. The proxy user name and password should be a String
.
If nil is given for the proxy URI
, this option is just ignored.
If :proxy and :proxy_http_basic_authentication is specified, ArgumentError
is raised.
Synopsis:
:http_basic_authentication=>[user, password]
If :http_basic_authentication is specified, the value should be an array which contains 2 strings: username and password. It is used for HTTP Basic authentication defined by RFC 2617.
Synopsis:
:content_length_proc => lambda {|content_length| ... }
If :content_length_proc option is specified, the option value procedure is called before actual transfer is started. It takes one argument, which is expected content length in bytes.
If two or more transfers are performed by HTTP redirection, the procedure is called only once for the last transfer.
When expected content length is unknown, the procedure is called with nil. This happens when the HTTP response has no Content-Length header.
Synopsis:
:progress_proc => lambda {|size| ...}
If :progress_proc option is specified, the proc is called with one argument each time when ‘open’ gets content fragment from network. The argument size
is the accumulated transferred size in bytes.
If two or more transfer is done by HTTP redirection, the procedure is called only one for a last transfer.
:progress_proc and :content_length_proc are intended to be used for progress bar. For example, it can be implemented as follows using Ruby/ProgressBar.
pbar = nil open("http://...", :content_length_proc => lambda {|t| if t && 0 < t pbar = ProgressBar.new("...", t) pbar.file_transfer_mode end }, :progress_proc => lambda {|s| pbar.set s if pbar }) {|f| ... }
Synopsis:
:read_timeout=>nil (no timeout) :read_timeout=>10 (10 second)
:read_timeout option specifies a timeout of read for http connections.
Synopsis:
:open_timeout=>nil (no timeout) :open_timeout=>10 (10 second)
:open_timeout option specifies a timeout of open for http connections.
Synopsis:
:ssl_ca_cert=>filename or an Array of filenames
:ssl_ca_cert is used to specify CA certificate for SSL. If it is given, default certificates are not used.
Synopsis:
:ssl_verify_mode=>mode
:ssl_verify_mode is used to specify openssl verify mode.
Synopsis:
:ssl_min_version=>:TLS1_2
:ssl_min_version option specifies the minimum allowed SSL/TLS protocol version. See also OpenSSL::SSL::SSLContext#min_version=
.
Synopsis:
:ssl_max_version=>:TLS1_2
:ssl_max_version option specifies the maximum allowed SSL/TLS protocol version. See also OpenSSL::SSL::SSLContext#max_version=
.
Synopsis:
:ftp_active_mode=>bool
:ftp_active_mode => true
is used to make ftp active mode. Ruby
1.9 uses passive mode by default. Note that the active mode is default in Ruby
1.8 or prior.
Synopsis:
:redirect=>bool
:redirect
is true by default. :redirect => false
is used to disable all HTTP redirects.
OpenURI::HTTPRedirect
exception raised on redirection. Using true
also means that redirections between http and ftp are permitted.
Synopsis:
:max_redirects=>int
Number of HTTP redirects allowed before OpenURI::TooManyRedirects
is raised. The default is 64.
Synopsis:
:request_specific_fields => {} :request_specific_fields => lambda {|url| ...}
:request_specific_fields option allows specifying custom header fields that are sent with the HTTP request. It can be passed as a Hash
or a Proc
that gets evaluated on each request and returns a Hash
of header fields.
If a Hash
is provided, it specifies the headers only for the initial request and these headers will not be sent on redirects.
If a Proc
is provided, it will be executed for each request including redirects, allowing dynamic header customization based on the request URL. It is important that the Proc
returns a Hash
. And this Hash
specifies the headers to be sent with the request.
For Example with Hash
URI.open("http://...", request_specific_fields: {"Authorization" => "token dummy"}) {|f| ... }
For Example with Proc:
URI.open("http://...", request_specific_fields: lambda { |uri| if uri.host == "example.com" {"Authorization" => "token dummy"} else {} end }) {|f| ... }
Adds a separated list. The list is separated by comma with breakable space, by default.
seplist
iterates the list
using iter_method
. It yields each object to the block given for seplist
. The procedure separator_proc
is called between each yields.
If the iteration is zero times, separator_proc
is not called at all.
If separator_proc
is nil or not given, +lambda { comma_breakable
}+ is used. If iter_method
is not given, :each is used.
For example, following 3 code fragments has similar effect.
q.seplist([1,2,3]) {|v| xxx v } q.seplist([1,2,3], lambda { q.comma_breakable }, :each) {|v| xxx v } xxx 1 q.comma_breakable xxx 2 q.comma_breakable xxx 3
Create a new repository for the given filepath.
Generate a random base64 string.
The argument n specifies the length, in bytes, of the random number to be generated. The length of the result string is about 4/3 of n.
If n is not specified or is nil, 16 is assumed. It may be larger in the future.
The result may contain A-Z, a-z, 0-9, “+”, “/” and “=”.
require 'random/formatter' Random.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A==" # or prng = Random.new prng.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="
See RFC 3548 for the definition of base64.