rbs 1.4.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +10 -0
  3. data/CHANGELOG.md +52 -0
  4. data/Gemfile +2 -0
  5. data/Steepfile +9 -1
  6. data/core/builtin.rbs +1 -1
  7. data/core/file.rbs +3 -1
  8. data/core/global_variables.rbs +3 -3
  9. data/core/io/wait.rbs +37 -0
  10. data/core/io.rbs +6 -4
  11. data/core/ractor.rbs +779 -0
  12. data/core/string_io.rbs +3 -5
  13. data/docs/collection.md +116 -0
  14. data/lib/rbs/builtin_names.rb +1 -0
  15. data/lib/rbs/cli.rb +93 -2
  16. data/lib/rbs/collection/cleaner.rb +29 -0
  17. data/lib/rbs/collection/config/lockfile_generator.rb +95 -0
  18. data/lib/rbs/collection/config.rb +85 -0
  19. data/lib/rbs/collection/installer.rb +27 -0
  20. data/lib/rbs/collection/sources/git.rb +147 -0
  21. data/lib/rbs/collection/sources/rubygems.rb +40 -0
  22. data/lib/rbs/collection/sources/stdlib.rb +38 -0
  23. data/lib/rbs/collection/sources.rb +22 -0
  24. data/lib/rbs/collection.rb +13 -0
  25. data/lib/rbs/environment_loader.rb +12 -0
  26. data/lib/rbs/errors.rb +2 -0
  27. data/lib/rbs/repository.rb +13 -7
  28. data/lib/rbs/validator.rb +4 -1
  29. data/lib/rbs/version.rb +1 -1
  30. data/lib/rbs.rb +1 -0
  31. data/sig/builtin_names.rbs +1 -0
  32. data/sig/cli.rbs +5 -0
  33. data/sig/collection/cleaner.rbs +13 -0
  34. data/sig/collection/collections.rbs +112 -0
  35. data/sig/collection/config.rbs +69 -0
  36. data/sig/collection/installer.rbs +15 -0
  37. data/sig/collection.rbs +4 -0
  38. data/sig/environment_loader.rbs +3 -0
  39. data/sig/polyfill.rbs +12 -3
  40. data/sig/repository.rbs +4 -0
  41. data/stdlib/digest/0/digest.rbs +418 -0
  42. data/stdlib/objspace/0/objspace.rbs +406 -0
  43. data/stdlib/openssl/0/openssl.rbs +1 -1
  44. data/stdlib/tempfile/0/tempfile.rbs +270 -0
  45. data/steep/Gemfile.lock +10 -10
  46. metadata +24 -3
@@ -0,0 +1,69 @@
1
+ module RBS
2
+ module Collection
3
+ # This class represent the configration file.
4
+ class Config
5
+ class LockfileGenerator
6
+ attr_reader config: Config
7
+ attr_reader lock: Config?
8
+ attr_reader lock_path: Pathname
9
+ attr_reader gemfile_lock: Bundler::LockfileParser
10
+
11
+ def self.generate: (config_path: Pathname, gemfile_lock_path: Pathname, ?with_lockfile: boolish) -> Config
12
+
13
+ def initialize: (config_path: Pathname, gemfile_lock_path: Pathname, with_lockfile: boolish) -> void
14
+
15
+ def generate: () -> Config
16
+
17
+ private
18
+
19
+ def assign_gem: (gem_name: String, version: String?) -> void
20
+
21
+ def upsert_gem: (gem_entry? old, gem_entry new) -> void
22
+
23
+ def gemfile_lock_gems: () { (untyped) -> void } -> void
24
+
25
+ def remove_ignored_gems!: () -> void
26
+
27
+ def find_source: (gem_name: String) -> untyped
28
+
29
+ def find_best_version: (version: String?, versions: Array[String]) -> Gem::Version
30
+ end
31
+
32
+ PATH: Pathname
33
+
34
+ type gem_entry = {
35
+ 'name' => String,
36
+ 'version' => String?,
37
+ 'ignore' => boolish,
38
+ 'source' => Sources::source_entry?
39
+ }
40
+
41
+ @config_path: Pathname
42
+
43
+ def self.generate_lockfile: (config_path: Pathname, gemfile_lock_path: Pathname, ?with_lockfile: boolish) -> Config
44
+
45
+ def self.from_path: (Pathname path) -> Config
46
+
47
+ def self.lockfile_of: (Pathname config_path) -> Config?
48
+
49
+ def self.to_lockfile_path: (Pathname config_path) -> Pathname
50
+
51
+ # config_path is necessary to resolve relative repo_path
52
+ def initialize: (untyped data, config_path: Pathname) -> void
53
+
54
+ def add_gem: (untyped gem) -> untyped
55
+
56
+ def gem: (String gem_name) -> untyped
57
+
58
+ def repo_path: () -> Pathname
59
+
60
+ def sources: () -> Array[Sources::_Source]
61
+
62
+ def dump_to: (Pathname) -> void
63
+
64
+ def gems: () -> Array[untyped]
65
+
66
+ def check_rbs_availability!: () -> void
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,15 @@
1
+ module RBS
2
+ module Collection
3
+ class Installer
4
+ attr_reader lockfile: Config
5
+ attr_reader stdout: CLI::_IO
6
+
7
+ def initialize: (lockfile_path: Pathname, ?stdout: CLI::_IO) -> void
8
+ def install_from_lockfile: () -> void
9
+
10
+ private
11
+
12
+ def source_for: (Config::gem_entry) -> Sources::_Source
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ module RBS
2
+ module Collection
3
+ end
4
+ end
@@ -78,6 +78,9 @@ module RBS
78
78
  def add: (path: Pathname) -> void
79
79
  | (library: String, version: String?) -> void
80
80
 
81
+ # Add repository path and libraries via rbs_collection.lock.yaml.
82
+ def add_collection: (Collection::Config collection_config) -> void
83
+
81
84
  # This is helper function to test if RBS for a library is available or not.
82
85
  #
83
86
  def has_library?: (library: String, version: String?) -> bool
data/sig/polyfill.rbs CHANGED
@@ -1,6 +1,3 @@
1
- module Kernel
2
- end
3
-
4
1
  module Gem
5
2
  class Specification
6
3
  attr_reader version (): Version
@@ -16,3 +13,15 @@ module Enumerable[unchecked out Elem]
16
13
  | [U] () { (Elem) -> U } -> Array[U]
17
14
  | ...
18
15
  end
16
+
17
+ module Bundler
18
+ class LockfileParser
19
+ def initialize: (String) -> void
20
+ def specs: () -> Array[LazySpecification]
21
+ end
22
+
23
+ class LazySpecification
24
+ def name: () -> String
25
+ def version: () -> String
26
+ end
27
+ end
data/sig/repository.rbs CHANGED
@@ -57,6 +57,10 @@ module RBS
57
57
 
58
58
  attr_reader gems: Hash[String, GemRBS]
59
59
 
60
+ def self.default: () -> instance
61
+
62
+ def self.find_best_version: (Gem::Version? version, Array[Gem::Version] candidates) -> Gem::Version
63
+
60
64
  # An optional keyword argument `no_stdlib` is to skip adding directory for stdlib classes.
61
65
  # Passing truthy value will skip loading stdlib. (You can add the stdlib root by yourself.)
62
66
  #
@@ -0,0 +1,418 @@
1
+ # This module provides a framework for message digest libraries.
2
+ #
3
+ # You may want to look at OpenSSL::Digest as it supports more algorithms.
4
+ #
5
+ # A cryptographic hash function is a procedure that takes data and returns a
6
+ # fixed bit string: the hash value, also known as *digest*. Hash functions are
7
+ # also called one-way functions, it is easy to compute a digest from a message,
8
+ # but it is infeasible to generate a message from a digest.
9
+ #
10
+ # ## Examples
11
+ #
12
+ # require 'digest'
13
+ #
14
+ # # Compute a complete digest
15
+ # Digest::SHA256.digest 'message' #=> "\xABS\n\x13\xE4Y..."
16
+ #
17
+ # sha256 = Digest::SHA256.new
18
+ # sha256.digest 'message' #=> "\xABS\n\x13\xE4Y..."
19
+ #
20
+ # # Other encoding formats
21
+ # Digest::SHA256.hexdigest 'message' #=> "ab530a13e459..."
22
+ # Digest::SHA256.base64digest 'message' #=> "q1MKE+RZFJgr..."
23
+ #
24
+ # # Compute digest by chunks
25
+ # md5 = Digest::MD5.new
26
+ # md5.update 'message1'
27
+ # md5 << 'message2' # << is an alias for update
28
+ #
29
+ # md5.hexdigest #=> "94af09c09bb9..."
30
+ #
31
+ # # Compute digest for a file
32
+ # sha256 = Digest::SHA256.file 'testfile'
33
+ # sha256.hexdigest
34
+ #
35
+ # Additionally digests can be encoded in "bubble babble" format as a sequence of
36
+ # consonants and vowels which is more recognizable and comparable than a
37
+ # hexadecimal digest.
38
+ #
39
+ # require 'digest/bubblebabble'
40
+ #
41
+ # Digest::SHA256.bubblebabble 'message' #=> "xopoh-fedac-fenyh-..."
42
+ #
43
+ # See the bubble babble specification at
44
+ # http://web.mit.edu/kenta/www/one/bubblebabble/spec/jrtrjwzi/draft-huima-01.txt
45
+ # .
46
+ #
47
+ # ## Digest algorithms
48
+ #
49
+ # Different digest algorithms (or hash functions) are available:
50
+ #
51
+ # MD5
52
+ # : See RFC 1321 The MD5 Message-Digest Algorithm
53
+ # RIPEMD-160
54
+ # : As Digest::RMD160. See
55
+ # http://homes.esat.kuleuven.be/~bosselae/ripemd160.html.
56
+ # SHA1
57
+ # : See FIPS 180 Secure Hash Standard.
58
+ # SHA2 family
59
+ # : See FIPS 180 Secure Hash Standard which defines the following algorithms:
60
+ # * SHA512
61
+ # * SHA384
62
+ # * SHA256
63
+ #
64
+ #
65
+ #
66
+ # The latest versions of the FIPS publications can be found here:
67
+ # http://csrc.nist.gov/publications/PubsFIPS.html.
68
+ module Digest
69
+ # Returns a BubbleBabble encoded version of a given *string*.
70
+ #
71
+ def self.bubblebabble: (String) -> String
72
+
73
+ def self.const_missing: (Symbol name) -> singleton(::Digest::Base)
74
+
75
+ # Generates a hex-encoded version of a given *string*.
76
+ #
77
+ def self.hexencode: (String) -> String
78
+
79
+ private
80
+
81
+ def bubblebabble: (String) -> String
82
+
83
+ def hexencode: (String) -> String
84
+ end
85
+
86
+ # A mutex for Digest().
87
+ Digest::REQUIRE_MUTEX: Thread::Mutex
88
+
89
+ # This module provides instance methods for a digest implementation object to
90
+ # calculate message digest values.
91
+ module Digest::Instance
92
+ public
93
+
94
+ # Updates the digest using a given *string* and returns self.
95
+ #
96
+ # The update() method and the left-shift operator are overridden by each
97
+ # implementation subclass. (One should be an alias for the other)
98
+ #
99
+ def <<: (String) -> self
100
+
101
+ # If a string is given, checks whether it is equal to the hex-encoded hash value
102
+ # of the digest object. If another digest instance is given, checks whether
103
+ # they have the same hash value. Otherwise returns false.
104
+ #
105
+ def ==: (::Digest::Instance | String) -> bool
106
+
107
+ # If none is given, returns the resulting hash value of the digest in a base64
108
+ # encoded form, keeping the digest's state.
109
+ #
110
+ # If a `string` is given, returns the hash value for the given `string` in a
111
+ # base64 encoded form, resetting the digest to the initial state before and
112
+ # after the process.
113
+ #
114
+ # In either case, the return value is properly padded with '=' and contains no
115
+ # line feeds.
116
+ #
117
+ def base64digest: (?String? str) -> String
118
+
119
+ # Returns the resulting hash value and resets the digest to the initial state.
120
+ #
121
+ def base64digest!: () -> String
122
+
123
+ # Returns the block length of the digest.
124
+ #
125
+ # This method is overridden by each implementation subclass.
126
+ #
127
+ def block_length: () -> Integer
128
+
129
+ # Returns the resulting hash value in a Bubblebabble encoded form.
130
+ #
131
+ def bubblebabble: () -> String
132
+
133
+ # If none is given, returns the resulting hash value of the digest, keeping the
134
+ # digest's state.
135
+ #
136
+ # If a *string* is given, returns the hash value for the given *string*,
137
+ # resetting the digest to the initial state before and after the process.
138
+ #
139
+ def digest: (?String) -> String
140
+
141
+ # Returns the resulting hash value and resets the digest to the initial state.
142
+ #
143
+ def digest!: () -> String
144
+
145
+ # Returns the length of the hash value of the digest.
146
+ #
147
+ # This method should be overridden by each implementation subclass. If not,
148
+ # digest_obj.digest().length() is returned.
149
+ #
150
+ def digest_length: () -> Integer
151
+
152
+ # Updates the digest with the contents of a given file *name* and returns self.
153
+ #
154
+ def file: (String name) -> self
155
+
156
+ # If none is given, returns the resulting hash value of the digest in a
157
+ # hex-encoded form, keeping the digest's state.
158
+ #
159
+ # If a *string* is given, returns the hash value for the given *string* in a
160
+ # hex-encoded form, resetting the digest to the initial state before and after
161
+ # the process.
162
+ #
163
+ def hexdigest: (?String) -> String
164
+
165
+ # Returns the resulting hash value in a hex-encoded form and resets the digest
166
+ # to the initial state.
167
+ #
168
+ def hexdigest!: () -> String
169
+
170
+ # Creates a printable version of the digest object.
171
+ #
172
+ def inspect: () -> String
173
+
174
+ # Returns digest_obj.digest_length().
175
+ #
176
+ def length: () -> Integer
177
+
178
+ # Returns a new, initialized copy of the digest object. Equivalent to
179
+ # digest_obj.clone().reset().
180
+ #
181
+ def new: () -> ::Digest::Base
182
+
183
+ # Resets the digest to the initial state and returns self.
184
+ #
185
+ # This method is overridden by each implementation subclass.
186
+ #
187
+ def reset: () -> self
188
+
189
+ # Returns digest_obj.digest_length().
190
+ #
191
+ def size: () -> Integer
192
+
193
+ # Returns digest_obj.hexdigest().
194
+ #
195
+ def to_s: () -> String
196
+
197
+ # Updates the digest using a given *string* and returns self.
198
+ #
199
+ # The update() method and the left-shift operator are overridden by each
200
+ # implementation subclass. (One should be an alias for the other)
201
+ #
202
+ def update: (String) -> self
203
+
204
+ private
205
+
206
+ # Finishes the digest and returns the resulting hash value.
207
+ #
208
+ # This method is overridden by each implementation subclass and often made
209
+ # private, because some of those subclasses may leave internal data
210
+ # uninitialized. Do not call this method from outside. Use #digest!() instead,
211
+ # which ensures that internal data be reset for security reasons.
212
+ #
213
+ def finish: () -> self
214
+ end
215
+
216
+ # This module stands as a base class for digest implementation classes.
217
+ class Digest::Class
218
+ include ::Digest::Instance
219
+
220
+ # Returns the base64 encoded hash value of a given *string*. The return value
221
+ # is properly padded with '=' and contains no line feeds.
222
+ #
223
+ def self.base64digest: (String str, *untyped) -> String
224
+
225
+ # Returns the BubbleBabble encoded hash value of a given *string*.
226
+ #
227
+ def self.bubblebabble: (String, *untyped) -> String
228
+
229
+ # Returns the hash value of a given *string*. This is equivalent to
230
+ # Digest::Class.new(*parameters).digest(string), where extra *parameters*, if
231
+ # any, are passed through to the constructor and the *string* is passed to
232
+ # #digest().
233
+ #
234
+ def self.digest: (String, *untyped) -> String
235
+
236
+ # Creates a digest object and reads a given file, *name*. Optional arguments are
237
+ # passed to the constructor of the digest class.
238
+ #
239
+ # p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
240
+ # # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
241
+ #
242
+ def self.file: (String name, *untyped) -> ::Digest::Class
243
+
244
+ # Returns the hex-encoded hash value of a given *string*. This is almost
245
+ # equivalent to Digest.hexencode(Digest::Class.new(*parameters).digest(string)).
246
+ #
247
+ def self.hexdigest: (String, *untyped) -> String
248
+
249
+ private
250
+
251
+ def initialize: () -> self
252
+ end
253
+
254
+ # This abstract class provides a common interface to message digest
255
+ # implementation classes written in C.
256
+ #
257
+ # ## Write a Digest subclass in C
258
+ # Digest::Base provides a common interface to message digest classes written in
259
+ # C. These classes must provide a struct of type rb_digest_metadata_t:
260
+ # typedef int (*rb_digest_hash_init_func_t)(void *);
261
+ # typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t);
262
+ # typedef int (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
263
+ #
264
+ # typedef struct {
265
+ # int api_version;
266
+ # size_t digest_len;
267
+ # size_t block_len;
268
+ # size_t ctx_size;
269
+ # rb_digest_hash_init_func_t init_func;
270
+ # rb_digest_hash_update_func_t update_func;
271
+ # rb_digest_hash_finish_func_t finish_func;
272
+ # } rb_digest_metadata_t;
273
+ #
274
+ # This structure must be set as an instance variable named `metadata` (without
275
+ # the +@+ in front of the name). By example:
276
+ # static const rb_digest_metadata_t sha1 = {
277
+ # RUBY_DIGEST_API_VERSION,
278
+ # SHA1_DIGEST_LENGTH,
279
+ # SHA1_BLOCK_LENGTH,
280
+ # sizeof(SHA1_CTX),
281
+ # (rb_digest_hash_init_func_t)SHA1_Init,
282
+ # (rb_digest_hash_update_func_t)SHA1_Update,
283
+ # (rb_digest_hash_finish_func_t)SHA1_Finish,
284
+ # };
285
+ #
286
+ # rb_ivar_set(cDigest_SHA1, rb_intern("metadata"),
287
+ # Data_Wrap_Struct(0, 0, 0, (void *)&sha1));
288
+ class Digest::Base < Digest::Class
289
+ public
290
+
291
+ # Update the digest using given *string* and return `self`.
292
+ #
293
+ def <<: (String) -> self
294
+
295
+ # Return the block length of the digest in bytes.
296
+ #
297
+ def block_length: () -> Integer
298
+
299
+ # Return the length of the hash value in bytes.
300
+ #
301
+ def digest_length: () -> Integer
302
+
303
+ # Reset the digest to its initial state and return `self`.
304
+ #
305
+ def reset: () -> self
306
+
307
+ # Update the digest using given *string* and return `self`.
308
+ #
309
+ def update: (String) -> self
310
+
311
+ private
312
+
313
+ def finish: () -> String
314
+
315
+ def initialize_copy: (::Digest::Base) -> self
316
+ end
317
+
318
+ # A class for calculating message digests using the SHA-1 Secure Hash Algorithm
319
+ # by NIST (the US' National Institute of Standards and Technology), described in
320
+ # FIPS PUB 180-1.
321
+ #
322
+ # See Digest::Instance for digest API.
323
+ #
324
+ # SHA-1 calculates a digest of 160 bits (20 bytes).
325
+ #
326
+ # ## Examples
327
+ # require 'digest'
328
+ #
329
+ # # Compute a complete digest
330
+ # Digest::SHA1.hexdigest 'abc' #=> "a9993e36..."
331
+ #
332
+ # # Compute digest by chunks
333
+ # sha1 = Digest::SHA1.new # =>#<Digest::SHA1>
334
+ # sha1.update "ab"
335
+ # sha1 << "c" # alias for #update
336
+ # sha1.hexdigest # => "a9993e36..."
337
+ #
338
+ # # Use the same object to compute another digest
339
+ # sha1.reset
340
+ # sha1 << "message"
341
+ # sha1.hexdigest # => "6f9b9af3..."
342
+ class Digest::SHA1 < Digest::Base
343
+ end
344
+
345
+ # A class for calculating message digests using the MD5 Message-Digest Algorithm
346
+ # by RSA Data Security, Inc., described in RFC1321.
347
+ #
348
+ # MD5 calculates a digest of 128 bits (16 bytes).
349
+ #
350
+ # ## Examples
351
+ # require 'digest'
352
+ #
353
+ # # Compute a complete digest
354
+ # Digest::MD5.hexdigest 'abc' #=> "90015098..."
355
+ #
356
+ # # Compute digest by chunks
357
+ # md5 = Digest::MD5.new # =>#<Digest::MD5>
358
+ # md5.update "ab"
359
+ # md5 << "c" # alias for #update
360
+ # md5.hexdigest # => "90015098..."
361
+ #
362
+ # # Use the same object to compute another digest
363
+ # md5.reset
364
+ # md5 << "message"
365
+ # md5.hexdigest # => "78e73102..."
366
+ class Digest::MD5 < Digest::Base
367
+ end
368
+
369
+ # A class for calculating message digests using RIPEMD-160 cryptographic hash
370
+ # function, designed by Hans Dobbertin, Antoon Bosselaers, and Bart Preneel.
371
+ #
372
+ # RMD160 calculates a digest of 160 bits (20 bytes).
373
+ #
374
+ # ## Examples
375
+ # require 'digest'
376
+ #
377
+ # # Compute a complete digest
378
+ # Digest::RMD160.hexdigest 'abc' #=> "8eb208f7..."
379
+ #
380
+ # # Compute digest by chunks
381
+ # rmd160 = Digest::RMD160.new # =>#<Digest::RMD160>
382
+ # rmd160.update "ab"
383
+ # rmd160 << "c" # alias for #update
384
+ # rmd160.hexdigest # => "8eb208f7..."
385
+ #
386
+ # # Use the same object to compute another digest
387
+ # rmd160.reset
388
+ # rmd160 << "message"
389
+ # rmd160.hexdigest # => "1dddbe1b..."
390
+ class Digest::RMD160 < Digest::Base
391
+ end
392
+
393
+ class Digest::SHA256 < Digest::Base
394
+ end
395
+
396
+ class Digest::SHA384 < Digest::Base
397
+ end
398
+
399
+ class Digest::SHA512 < Digest::Base
400
+ end
401
+
402
+ class Object
403
+ # Returns a Digest subclass by `name` in a thread-safe manner even when
404
+ # on-demand loading is involved.
405
+ #
406
+ # require 'digest'
407
+ #
408
+ # Digest("MD5")
409
+ # # => Digest::MD5
410
+ #
411
+ # Digest(:SHA256)
412
+ # # => Digest::SHA256
413
+ #
414
+ # Digest(:Foo)
415
+ # # => LoadError: library not found for class Digest::Foo -- digest/foo
416
+ #
417
+ def Digest: (String | Symbol name) -> singleton(::Digest::Base)
418
+ end