Skip to content

Commit 955a9cb

Browse files
authored
Merge pull request #2661 from ksss/random-formatter
Split `Random::Formatter` to core and stdlib
2 parents 3881171 + 887d2f9 commit 955a9cb

File tree

7 files changed

+308
-155
lines changed

7 files changed

+308
-155
lines changed

core/rbs/unnamed/random.rbs

Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -146,56 +146,6 @@ module RBS
146146
#
147147
%a{annotate:rdoc:copy:Random::Formatter}
148148
module Random_Formatter
149-
# <!--
150-
# rdoc-file=lib/random/formatter.rb
151-
# - base64(n=nil)
152-
# -->
153-
# Generate a random base64 string.
154-
#
155-
# The argument *n* specifies the length, in bytes, of the random number to be
156-
# generated. The length of the result string is about 4/3 of *n*.
157-
#
158-
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
159-
# future.
160-
#
161-
# The result may contain A-Z, a-z, 0-9, "+", "/" and "=".
162-
#
163-
# require 'random/formatter'
164-
#
165-
# Random.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A=="
166-
# # or
167-
# prng = Random.new
168-
# prng.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="
169-
#
170-
# See RFC 3548 for the definition of base64.
171-
#
172-
%a{annotate:rdoc:copy:Random::Formatter#base64}
173-
def base64: (?Integer? n) -> String
174-
175-
# <!--
176-
# rdoc-file=lib/random/formatter.rb
177-
# - hex(n=nil)
178-
# -->
179-
# Generate a random hexadecimal string.
180-
#
181-
# The argument *n* specifies the length, in bytes, of the random number to be
182-
# generated. The length of the resulting hexadecimal string is twice of *n*.
183-
#
184-
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
185-
# future.
186-
#
187-
# The result may contain 0-9 and a-f.
188-
#
189-
# require 'random/formatter'
190-
#
191-
# Random.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
192-
# # or
193-
# prng = Random.new
194-
# prng.hex #=> "91dc3bfb4de5b11d029d376634589b61"
195-
#
196-
%a{annotate:rdoc:copy:Random::Formatter#hex}
197-
def hex: (?Integer? n) -> String
198-
199149
# <!-- rdoc-file=random.c -->
200150
# Generates formatted random number from raw random bytes. See Random#rand.
201151
#
@@ -208,9 +158,6 @@ module RBS
208158
| (::Range[Integer] n) -> Integer
209159
| (::Range[Numeric] n) -> Numeric
210160

211-
%a{annotate:rdoc:copy:Random::Formatter#random_byte}
212-
def random_bytes: (?Integer? n) -> String
213-
214161
# <!--
215162
# rdoc-file=random.c
216163
# - prng.random_number -> float
@@ -230,94 +177,6 @@ module RBS
230177
| (?::Range[Float]? n) -> Float
231178
| (?::Range[Integer]? n) -> Integer
232179
| (?::Range[Numeric]? n) -> Numeric
233-
234-
# <!--
235-
# rdoc-file=lib/random/formatter.rb
236-
# - urlsafe_base64(n=nil, padding=false)
237-
# -->
238-
# Generate a random URL-safe base64 string.
239-
#
240-
# The argument *n* specifies the length, in bytes, of the random number to be
241-
# generated. The length of the result string is about 4/3 of *n*.
242-
#
243-
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
244-
# future.
245-
#
246-
# The boolean argument *padding* specifies the padding. If it is false or nil,
247-
# padding is not generated. Otherwise padding is generated. By default, padding
248-
# is not generated because "=" may be used as a URL delimiter.
249-
#
250-
# The result may contain A-Z, a-z, 0-9, "-" and "_". "=" is also used if
251-
# *padding* is true.
252-
#
253-
# require 'random/formatter'
254-
#
255-
# Random.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
256-
# # or
257-
# prng = Random.new
258-
# prng.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
259-
#
260-
# prng.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
261-
# prng.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
262-
#
263-
# See RFC 3548 for the definition of URL-safe base64.
264-
#
265-
%a{annotate:rdoc:copy:Random::Formatter#urlsafe_base64}
266-
def urlsafe_base64: (?Integer? n, ?boolish padding) -> String
267-
268-
# <!--
269-
# rdoc-file=lib/random/formatter.rb
270-
# - uuid()
271-
# -->
272-
# Generate a random v4 UUID (Universally Unique IDentifier).
273-
#
274-
# require 'random/formatter'
275-
#
276-
# Random.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
277-
# Random.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
278-
# # or
279-
# prng = Random.new
280-
# prng.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
281-
#
282-
# The version 4 UUID is purely random (except the version). It doesn't contain
283-
# meaningful information such as MAC addresses, timestamps, etc.
284-
#
285-
# The result contains 122 random bits (15.25 random bytes).
286-
#
287-
# See [RFC9562](https://www.rfc-editor.org/rfc/rfc9562) for details of UUIDv4.
288-
#
289-
%a{annotate:rdoc:copy:Random::Formatter#uuid}
290-
def uuid: () -> String
291-
292-
# <!--
293-
# rdoc-file=lib/random/formatter.rb
294-
# - alphanumeric(n = nil, chars: ALPHANUMERIC)
295-
# -->
296-
# Generate a random alphanumeric string.
297-
#
298-
# The argument *n* specifies the length, in characters, of the alphanumeric
299-
# string to be generated. The argument *chars* specifies the character list
300-
# which the result is consist of.
301-
#
302-
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
303-
# future.
304-
#
305-
# The result may contain A-Z, a-z and 0-9, unless *chars* is specified.
306-
#
307-
# require 'random/formatter'
308-
#
309-
# Random.alphanumeric #=> "2BuBuLf3WfSKyQbR"
310-
# # or
311-
# prng = Random.new
312-
# prng.alphanumeric(10) #=> "i6K93NdqiH"
313-
#
314-
# Random.alphanumeric(4, chars: [*"0".."9"]) #=> "2952"
315-
# # or
316-
# prng = Random.new
317-
# prng.alphanumeric(10, chars: [*"!".."/"]) #=> ",.,++%/''."
318-
#
319-
%a{annotate:rdoc:copy:Random::Formatter#alphanumeric}
320-
def alphanumeric: (?Numeric?, ?chars: Array[String]) -> String
321180
end
322181
end
323182
end
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
module RBS
2+
module Unnamed
3+
module Random_Formatter
4+
# <!--
5+
# rdoc-file=lib/random/formatter.rb
6+
# - base64(n=nil)
7+
# -->
8+
# Generate a random base64 string.
9+
#
10+
# The argument *n* specifies the length, in bytes, of the random number to be
11+
# generated. The length of the result string is about 4/3 of *n*.
12+
#
13+
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
14+
# future.
15+
#
16+
# The result may contain A-Z, a-z, 0-9, "+", "/" and "=".
17+
#
18+
# require 'random/formatter'
19+
#
20+
# Random.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A=="
21+
# # or
22+
# prng = Random.new
23+
# prng.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="
24+
#
25+
# See RFC 3548 for the definition of base64.
26+
#
27+
%a{annotate:rdoc:copy:Random::Formatter#base64}
28+
def base64: (?Integer? n) -> String
29+
30+
# <!--
31+
# rdoc-file=lib/random/formatter.rb
32+
# - hex(n=nil)
33+
# -->
34+
# Generate a random hexadecimal string.
35+
#
36+
# The argument *n* specifies the length, in bytes, of the random number to be
37+
# generated. The length of the resulting hexadecimal string is twice of *n*.
38+
#
39+
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
40+
# future.
41+
#
42+
# The result may contain 0-9 and a-f.
43+
#
44+
# require 'random/formatter'
45+
#
46+
# Random.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
47+
# # or
48+
# prng = Random.new
49+
# prng.hex #=> "91dc3bfb4de5b11d029d376634589b61"
50+
#
51+
%a{annotate:rdoc:copy:Random::Formatter#hex}
52+
def hex: (?Integer? n) -> String
53+
54+
# <!--
55+
# rdoc-file=lib/random/formatter.rb
56+
# - random_bytes(n=nil)
57+
# -->
58+
# Generate a random binary string.
59+
#
60+
# The argument *n* specifies the length of the result string.
61+
#
62+
# If *n* is not specified or is nil, 16 is assumed. It may be larger in future.
63+
#
64+
# The result may contain any byte: "x00" - "xff".
65+
#
66+
# require 'random/formatter'
67+
#
68+
# Random.random_bytes #=> "\xD8\\\xE0\xF4\r\xB2\xFC*WM\xFF\x83\x18\xF45\xB6"
69+
# # or
70+
# prng = Random.new
71+
# prng.random_bytes #=> "m\xDC\xFC/\a\x00Uf\xB2\xB2P\xBD\xFF6S\x97"
72+
#
73+
%a{annotate:rdoc:copy:Random::Formatter#random_bytes}
74+
def random_bytes: (?Integer? n) -> String
75+
76+
# <!--
77+
# rdoc-file=lib/random/formatter.rb
78+
# - urlsafe_base64(n=nil, padding=false)
79+
# -->
80+
# Generate a random URL-safe base64 string.
81+
#
82+
# The argument *n* specifies the length, in bytes, of the random number to be
83+
# generated. The length of the result string is about 4/3 of *n*.
84+
#
85+
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
86+
# future.
87+
#
88+
# The boolean argument *padding* specifies the padding. If it is false or nil,
89+
# padding is not generated. Otherwise padding is generated. By default, padding
90+
# is not generated because "=" may be used as a URL delimiter.
91+
#
92+
# The result may contain A-Z, a-z, 0-9, "-" and "_". "=" is also used if
93+
# *padding* is true.
94+
#
95+
# require 'random/formatter'
96+
#
97+
# Random.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"
98+
# # or
99+
# prng = Random.new
100+
# prng.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
101+
#
102+
# prng.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="
103+
# prng.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
104+
#
105+
# See RFC 3548 for the definition of URL-safe base64.
106+
#
107+
def urlsafe_base64: (?Integer? n, ?boolish padding) -> String
108+
109+
# <!--
110+
# rdoc-file=lib/random/formatter.rb
111+
# - uuid()
112+
# -->
113+
# Generate a random v4 UUID (Universally Unique IDentifier).
114+
#
115+
# require 'random/formatter'
116+
#
117+
# Random.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
118+
# Random.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
119+
# # or
120+
# prng = Random.new
121+
# prng.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"
122+
#
123+
# The version 4 UUID is purely random (except the version). It doesn't contain
124+
# meaningful information such as MAC addresses, timestamps, etc.
125+
#
126+
# The result contains 122 random bits (15.25 random bytes).
127+
#
128+
# See [RFC9562](https://www.rfc-editor.org/rfc/rfc9562) for details of UUIDv4.
129+
#
130+
def uuid: () -> String
131+
132+
# <!--
133+
# rdoc-file=lib/random/formatter.rb
134+
# - alphanumeric(n = nil, chars: ALPHANUMERIC)
135+
# -->
136+
# Generate a random alphanumeric string.
137+
#
138+
# The argument *n* specifies the length, in characters, of the alphanumeric
139+
# string to be generated. The argument *chars* specifies the character list
140+
# which the result is consist of.
141+
#
142+
# If *n* is not specified or is nil, 16 is assumed. It may be larger in the
143+
# future.
144+
#
145+
# The result may contain A-Z, a-z and 0-9, unless *chars* is specified.
146+
#
147+
# require 'random/formatter'
148+
#
149+
# Random.alphanumeric #=> "2BuBuLf3WfSKyQbR"
150+
# # or
151+
# prng = Random.new
152+
# prng.alphanumeric(10) #=> "i6K93NdqiH"
153+
#
154+
# Random.alphanumeric(4, chars: [*"0".."9"]) #=> "2952"
155+
# # or
156+
# prng = Random.new
157+
# prng.alphanumeric(10, chars: [*"!".."/"]) #=> ",.,++%/''."
158+
#
159+
def alphanumeric: (?Numeric?, ?chars: Array[String]) -> String
160+
end
161+
end
162+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dependencies:
2+
- name: random-formatter

test/rbs/collection/config_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,10 @@ def test_generate_lockfile__dependency_source
795795
version: "0.3.0"
796796
source:
797797
type: rubygems
798+
- name: random-formatter
799+
version: "0"
800+
source:
801+
type: stdlib
798802
- name: securerandom
799803
version: "0"
800804
source:

0 commit comments

Comments
 (0)