Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 0 additions & 141 deletions core/rbs/unnamed/random.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -146,56 +146,6 @@ module RBS
#
%a{annotate:rdoc:copy:Random::Formatter}
module Random_Formatter
# <!--
# rdoc-file=lib/random/formatter.rb
# - base64(n=nil)
# -->
# 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.
#
%a{annotate:rdoc:copy:Random::Formatter#base64}
def base64: (?Integer? n) -> String

# <!--
# rdoc-file=lib/random/formatter.rb
# - hex(n=nil)
# -->
# Generate a random hexadecimal string.
#
# The argument *n* specifies the length, in bytes, of the random number to be
# generated. The length of the resulting hexadecimal string is twice of *n*.
#
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
# future.
#
# The result may contain 0-9 and a-f.
#
# require 'random/formatter'
#
# Random.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
# # or
# prng = Random.new
# prng.hex #=> "91dc3bfb4de5b11d029d376634589b61"
#
%a{annotate:rdoc:copy:Random::Formatter#hex}
def hex: (?Integer? n) -> String

# <!-- rdoc-file=random.c -->
# Generates formatted random number from raw random bytes. See Random#rand.
#
Expand All @@ -208,9 +158,6 @@ module RBS
| (::Range[Integer] n) -> Integer
| (::Range[Numeric] n) -> Numeric

%a{annotate:rdoc:copy:Random::Formatter#random_byte}
def random_bytes: (?Integer? n) -> String

# <!--
# rdoc-file=random.c
# - prng.random_number -> float
Expand All @@ -230,94 +177,6 @@ module RBS
| (?::Range[Float]? n) -> Float
| (?::Range[Integer]? n) -> Integer
| (?::Range[Numeric]? n) -> Numeric

# <!--
# rdoc-file=lib/random/formatter.rb
# - urlsafe_base64(n=nil, padding=false)
# -->
# Generate a random URL-safe 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 boolean argument *padding* specifies the padding. If it is false or nil,
# padding is not generated. Otherwise padding is generated. By default, padding
# is not generated because "=" may be used as a URL delimiter.
#
# The result may contain A-Z, a-z, 0-9, "-" and "_". "=" is also used if
# *padding* is true.
#
# require 'random/formatter'
#
# Random.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
# # or
# prng = Random.new
# prng.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
#
# prng.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
# prng.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
#
# See RFC 3548 for the definition of URL-safe base64.
#
%a{annotate:rdoc:copy:Random::Formatter#urlsafe_base64}
def urlsafe_base64: (?Integer? n, ?boolish padding) -> String

# <!--
# rdoc-file=lib/random/formatter.rb
# - uuid()
# -->
# Generate a random v4 UUID (Universally Unique IDentifier).
#
# require 'random/formatter'
#
# Random.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
# Random.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
# # or
# prng = Random.new
# prng.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
#
# The version 4 UUID is purely random (except the version). It doesn't contain
# meaningful information such as MAC addresses, timestamps, etc.
#
# The result contains 122 random bits (15.25 random bytes).
#
# See [RFC9562](https://www.rfc-editor.org/rfc/rfc9562) for details of UUIDv4.
#
%a{annotate:rdoc:copy:Random::Formatter#uuid}
def uuid: () -> String

# <!--
# rdoc-file=lib/random/formatter.rb
# - alphanumeric(n = nil, chars: ALPHANUMERIC)
# -->
# Generate a random alphanumeric string.
#
# The argument *n* specifies the length, in characters, of the alphanumeric
# string to be generated. The argument *chars* specifies the character list
# which the result is consist of.
#
# 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 and 0-9, unless *chars* is specified.
#
# require 'random/formatter'
#
# Random.alphanumeric #=> "2BuBuLf3WfSKyQbR"
# # or
# prng = Random.new
# prng.alphanumeric(10) #=> "i6K93NdqiH"
#
# Random.alphanumeric(4, chars: [*"0".."9"]) #=> "2952"
# # or
# prng = Random.new
# prng.alphanumeric(10, chars: [*"!".."/"]) #=> ",.,++%/''."
#
%a{annotate:rdoc:copy:Random::Formatter#alphanumeric}
def alphanumeric: (?Numeric?, ?chars: Array[String]) -> String
end
end
end
162 changes: 162 additions & 0 deletions stdlib/random-formatter/0/random-formatter.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
module RBS
module Unnamed
module Random_Formatter
# <!--
# rdoc-file=lib/random/formatter.rb
# - base64(n=nil)
# -->
# 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.
#
%a{annotate:rdoc:copy:Random::Formatter#base64}
def base64: (?Integer? n) -> String

# <!--
# rdoc-file=lib/random/formatter.rb
# - hex(n=nil)
# -->
# Generate a random hexadecimal string.
#
# The argument *n* specifies the length, in bytes, of the random number to be
# generated. The length of the resulting hexadecimal string is twice of *n*.
#
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
# future.
#
# The result may contain 0-9 and a-f.
#
# require 'random/formatter'
#
# Random.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
# # or
# prng = Random.new
# prng.hex #=> "91dc3bfb4de5b11d029d376634589b61"
#
%a{annotate:rdoc:copy:Random::Formatter#hex}
def hex: (?Integer? n) -> String

# <!--
# rdoc-file=lib/random/formatter.rb
# - random_bytes(n=nil)
# -->
# Generate a random binary string.
#
# The argument *n* specifies the length of the result string.
#
# If *n* is not specified or is nil, 16 is assumed. It may be larger in future.
#
# The result may contain any byte: "x00" - "xff".
#
# require 'random/formatter'
#
# Random.random_bytes #=> "\xD8\\\xE0\xF4\r\xB2\xFC*WM\xFF\x83\x18\xF45\xB6"
# # or
# prng = Random.new
# prng.random_bytes #=> "m\xDC\xFC/\a\x00Uf\xB2\xB2P\xBD\xFF6S\x97"
#
%a{annotate:rdoc:copy:Random::Formatter#random_bytes}
def random_bytes: (?Integer? n) -> String

# <!--
# rdoc-file=lib/random/formatter.rb
# - urlsafe_base64(n=nil, padding=false)
# -->
# Generate a random URL-safe 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 boolean argument *padding* specifies the padding. If it is false or nil,
# padding is not generated. Otherwise padding is generated. By default, padding
# is not generated because "=" may be used as a URL delimiter.
#
# The result may contain A-Z, a-z, 0-9, "-" and "_". "=" is also used if
# *padding* is true.
#
# require 'random/formatter'
#
# Random.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
# # or
# prng = Random.new
# prng.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
#
# prng.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
# prng.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
#
# See RFC 3548 for the definition of URL-safe base64.
#
def urlsafe_base64: (?Integer? n, ?boolish padding) -> String

# <!--
# rdoc-file=lib/random/formatter.rb
# - uuid()
# -->
# Generate a random v4 UUID (Universally Unique IDentifier).
#
# require 'random/formatter'
#
# Random.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
# Random.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
# # or
# prng = Random.new
# prng.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
#
# The version 4 UUID is purely random (except the version). It doesn't contain
# meaningful information such as MAC addresses, timestamps, etc.
#
# The result contains 122 random bits (15.25 random bytes).
#
# See [RFC9562](https://www.rfc-editor.org/rfc/rfc9562) for details of UUIDv4.
#
def uuid: () -> String

# <!--
# rdoc-file=lib/random/formatter.rb
# - alphanumeric(n = nil, chars: ALPHANUMERIC)
# -->
# Generate a random alphanumeric string.
#
# The argument *n* specifies the length, in characters, of the alphanumeric
# string to be generated. The argument *chars* specifies the character list
# which the result is consist of.
#
# 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 and 0-9, unless *chars* is specified.
#
# require 'random/formatter'
#
# Random.alphanumeric #=> "2BuBuLf3WfSKyQbR"
# # or
# prng = Random.new
# prng.alphanumeric(10) #=> "i6K93NdqiH"
#
# Random.alphanumeric(4, chars: [*"0".."9"]) #=> "2952"
# # or
# prng = Random.new
# prng.alphanumeric(10, chars: [*"!".."/"]) #=> ",.,++%/''."
#
def alphanumeric: (?Numeric?, ?chars: Array[String]) -> String
end
end
end
2 changes: 2 additions & 0 deletions stdlib/securerandom/0/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dependencies:
- name: random-formatter
4 changes: 4 additions & 0 deletions test/rbs/collection/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,10 @@ def test_generate_lockfile__dependency_source
version: "0.3.0"
source:
type: rubygems
- name: random-formatter
version: "0"
source:
type: stdlib
- name: securerandom
version: "0"
source:
Expand Down
Loading