Results for: "Data"

The UriFormatter handles URIs from user-input and escaping.

uf = Gem::UriFormatter.new 'example.com'

p uf.normalize #=> 'http://example.com'

Explains syntax errors based on their source

example:

source = "def foo; puts 'lol'" # Note missing end
explain ExplainSyntax.new(
  code_lines: CodeLine.from_source(source)
).call
explain.errors.first
# => "Unmatched keyword, missing `end' ?"

When the error cannot be determined by lexical counting then ripper is run against the input and the raw ripper errors returned.

Example:

source = "1 * " # Note missing a second number
explain ExplainSyntax.new(
  code_lines: CodeLine.from_source(source)
).call
explain.errors.first
# => "syntax error, unexpected end-of-input"

Converts a SyntaxError message to a path

Handles the case where the filename has a colon in it such as on a windows file system: github.com/ruby/syntax_suggest/issues/111

Example:

message = "/tmp/scratch:2:in `require_relative': /private/tmp/bad.rb:1: syntax error, unexpected `end' (SyntaxError)"
puts PathnameFromMessage.new(message).call.name
# => "/tmp/scratch.rb"

LDAP URI SCHEMA (described in RFC2255).

The default port for LDAPS URIs is 636, and the scheme is ‘ldaps:’ rather than ‘ldap:’. Other than that, LDAPS URIs are identical to LDAP URIs; see URI::LDAP.

No documentation available

AbstractSyntaxTree provides methods to parse Ruby code into abstract syntax trees. The nodes in the tree are instances of RubyVM::AbstractSyntaxTree::Node.

This module is MRI specific as it exposes implementation details of the MRI abstract syntax tree.

This module is experimental and its API is not stable, therefore it might change without notice. As examples, the order of children nodes is not guaranteed, the number of children nodes might change, there is no way to access children nodes by name, etc.

If you are looking for a stable API or an API working under multiple Ruby implementations, consider using the parser gem or Ripper. If you would like to make RubyVM::AbstractSyntaxTree stable, please join the discussion at bugs.ruby-lang.org/issues/14844.

File::Constants provides file-related constants. All possible file constants are listed in the documentation but they may not all be present on your platform.

If the underlying platform doesn’t define a constant the corresponding Ruby constant is not defined.

Your platform documentations (e.g. man open(2)) may describe more detailed information.

This module provides instance methods for a digest implementation object to calculate message digest values.

exception to wait for reading. see IO.select.

exception to wait for writing. see IO.select.

Provides classes and methods to request, create and validate RFC3161-compliant timestamps. Request may be used to either create requests from scratch or to parse existing requests that again can be used to request timestamps from a timestamp server, e.g. via the net/http. The resulting timestamp response may be parsed using Response.

Please note that Response is read-only and immutable. To create a Response, an instance of Factory as well as a valid Request are needed.

Create a Response:

#Assumes ts.p12 is a PKCS#12-compatible file with a private key
#and a certificate that has an extended key usage of 'timeStamping'
p12 = OpenSSL::PKCS12.new(File.binread('ts.p12'), 'pwd')
md = OpenSSL::Digest.new('SHA1')
hash = md.digest(data) #some binary data to be timestamped
req = OpenSSL::Timestamp::Request.new
req.algorithm = 'SHA1'
req.message_imprint = hash
req.policy_id = "1.2.3.4.5"
req.nonce = 42
fac = OpenSSL::Timestamp::Factory.new
fac.gen_time = Time.now
fac.serial_number = 1
timestamp = fac.create_timestamp(p12.key, p12.certificate, req)

Verify a timestamp response:

#Assume we have a timestamp token in a file called ts.der
ts = OpenSSL::Timestamp::Response.new(File.binread('ts.der'))
#Assume we have the Request for this token in a file called req.der
req = OpenSSL::Timestamp::Request.new(File.binread('req.der'))
# Assume the associated root CA certificate is contained in a
# DER-encoded file named root.cer
root = OpenSSL::X509::Certificate.new(File.binread('root.cer'))
# get the necessary intermediate certificates, available in
# DER-encoded form in inter1.cer and inter2.cer
inter1 = OpenSSL::X509::Certificate.new(File.binread('inter1.cer'))
inter2 = OpenSSL::X509::Certificate.new(File.binread('inter2.cer'))
ts.verify(req, root, inter1, inter2) -> ts or raises an exception if validation fails

Socket::Constants provides socket-related constants. All possible socket constants are listed in the documentation but they may not all be present on your platform.

If the underlying platform doesn’t define a constant the corresponding Ruby constant is not defined.

No documentation available
No documentation available
No documentation available
No documentation available

Mixin for holding meta-information.

Acceptable argument classes. Now contains DecimalInteger, OctalInteger and DecimalNumeric. See Acceptable argument classes (in source code).

Random number formatter.

Formats generated random numbers in many manners. When 'random/formatter' is required, several methods are added to empty core module Random::Formatter, making them available as Random’s instance and module methods.

Standard library SecureRandom is also extended with the module, and the methods described below are available as a module methods in it.

Examples

Generate random hexadecimal strings:

require 'random/formatter'

prng = Random.new
prng.hex(10) #=> "52750b30ffbc7de3b362"
prng.hex(10) #=> "92b15d6c8dc4beb5f559"
prng.hex(13) #=> "39b290146bea6ce975c37cfc23"
# or just
Random.hex #=> "1aed0c631e41be7f77365415541052ee"

Generate random base64 strings:

prng.base64(10) #=> "EcmTPZwWRAozdA=="
prng.base64(10) #=> "KO1nIU+p9DKxGg=="
prng.base64(12) #=> "7kJSM/MzBJI+75j8"
Random.base64(4) #=> "bsQ3fQ=="

Generate random binary strings:

prng.random_bytes(10) #=> "\016\t{\370g\310pbr\301"
prng.random_bytes(10) #=> "\323U\030TO\234\357\020\a\337"
Random.random_bytes(6) #=> "\xA1\xE6Lr\xC43"

Generate alphanumeric strings:

prng.alphanumeric(10) #=> "S8baxMJnPl"
prng.alphanumeric(10) #=> "aOxAg8BAJe"
Random.alphanumeric #=> "TmP9OsJHJLtaZYhP"

Generate UUIDs:

prng.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
prng.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
Random.uuid #=> "f14e0271-de96-45cc-8911-8910292a42cd"

All methods are available in the standard library SecureRandom, too:

SecureRandom.hex #=> "05b45376a30c67238eb93b16499e50cf"

Generate a random number in the given range as Random does

prng.random_number       #=> 0.5816771641321361
prng.random_number(1000) #=> 485
prng.random_number(1..6) #=> 3
prng.rand                #=> 0.5816771641321361
prng.rand(1000)          #=> 485
prng.rand(1..6)          #=> 3

Provides 3 methods for declaring when something is going away.

+deprecate(name, repl, year, month)+:

Indicate something may be removed on/after a certain date.

+rubygems_deprecate(name, replacement=:none)+:

Indicate something will be removed in the next major RubyGems version,
and (optionally) a replacement for it.

rubygems_deprecate_command:

Indicate a RubyGems command (in +lib/rubygems/commands/*.rb+) will be
removed in the next RubyGems version.

Also provides skip_during for temporarily turning off deprecation warnings. This is intended to be used in the test suite, so deprecation warnings don’t cause test failures if you need to make sure stderr is otherwise empty.

Example usage of deprecate and rubygems_deprecate:

class Legacy
  def self.some_class_method
    # ...
  end

  def some_instance_method
    # ...
  end

  def some_old_method
    # ...
  end

  extend Gem::Deprecate
  deprecate :some_instance_method, "X.z", 2011, 4
  rubygems_deprecate :some_old_method, "Modern#some_new_method"

  class << self
    extend Gem::Deprecate
    deprecate :some_class_method, :none, 2011, 4
  end
end

Example usage of rubygems_deprecate_command:

class Gem::Commands::QueryCommand < Gem::Command
  extend Gem::Deprecate
  rubygems_deprecate_command

  # ...
end

Example usage of skip_during:

class TestSomething < Gem::Testcase
  def test_some_thing_with_deprecations
    Gem::Deprecate.skip_during do
      actual_stdout, actual_stderr = capture_output do
        Gem.something_deprecated
      end
      assert_empty actual_stdout
      assert_equal(expected, actual_stderr)
    end
  end
end
No documentation available
No documentation available
No documentation available
No documentation available
Search took: 16ms  ·  Total Results: 1397