sorbet-runtime 0.5.5929 → 0.5.5939
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/types/enum.rb +11 -0
- data/lib/types/non_forcing_constants.rb +9 -3
- data/lib/types/private/methods/_methods.rb +25 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04d97cb5d3e3e445a08024c6b95add004935ab45528246ec2393da9bac31b194
|
4
|
+
data.tar.gz: cac1ed0237db0d1da9a82b8aa2f58c3520e7efc31bd799b63850d9016b47077f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cab4cdf08c2f0666cbdaf525d377ef7b71b020b0caae89fad46a79b778c9bea69bf93a0d0ae392ae222c7c0dfef43c064b0158c1487b748835d44a2f3e341e2
|
7
|
+
data.tar.gz: db822a985737d51983d53f1b339f68fb1bd86e56d9fffc05c787c18d3db75e790ba7117e9c4b15c09d00bc4178f5a0cf78b9a30e58a75d8d39daa940656c4e04
|
data/lib/types/enum.rb
CHANGED
@@ -57,6 +57,17 @@ class T::Enum
|
|
57
57
|
@values
|
58
58
|
end
|
59
59
|
|
60
|
+
# This exists for compatibility with the interface of `Hash` & mostly to support
|
61
|
+
# the HashEachMethods Rubocop.
|
62
|
+
sig {params(blk: T.nilable(T.proc.params(arg0: T.attached_class).void)).returns(T.any(T::Enumerator[T.attached_class], T::Array[T.attached_class]))}
|
63
|
+
def self.each_value(&blk)
|
64
|
+
if blk
|
65
|
+
values.each(&blk)
|
66
|
+
else
|
67
|
+
values.each
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
60
71
|
# Convert from serialized value to enum instance
|
61
72
|
#
|
62
73
|
# Note: It would have been nice to make this method final before people started overriding it.
|
@@ -4,8 +4,11 @@
|
|
4
4
|
module T::NonForcingConstants
|
5
5
|
# NOTE: This method is documented on the RBI in Sorbet's payload, so that it
|
6
6
|
# shows up in the hover/completion documentation via LSP.
|
7
|
-
T::Sig::WithoutRuntime.sig {params(val: BasicObject, klass: String).returns(T::Boolean)}
|
8
|
-
def self.non_forcing_is_a?(val, klass)
|
7
|
+
T::Sig::WithoutRuntime.sig {params(val: BasicObject, klass: String, package: T.nilable(String)).returns(T::Boolean)}
|
8
|
+
def self.non_forcing_is_a?(val, klass, package: nil)
|
9
|
+
# TODO(gdritter): once we have a runtime implementation of
|
10
|
+
# packages, we'll need to actually handle the `package` argument
|
11
|
+
# here.
|
9
12
|
method_name = "T::NonForcingConstants.non_forcing_is_a?"
|
10
13
|
if klass.empty?
|
11
14
|
raise ArgumentError.new("The string given to `#{method_name}` must not be empty")
|
@@ -18,7 +21,10 @@ module T::NonForcingConstants
|
|
18
21
|
parts.each do |part|
|
19
22
|
if current_klass.nil?
|
20
23
|
# First iteration
|
21
|
-
if part != ""
|
24
|
+
if part != "" && package.nil?
|
25
|
+
# if we've supplied a package, we're probably running in
|
26
|
+
# package mode, which means absolute references are
|
27
|
+
# meaningless
|
22
28
|
raise ArgumentError.new("The string given to `#{method_name}` must be an absolute constant reference that starts with `::`")
|
23
29
|
end
|
24
30
|
|
@@ -311,8 +311,12 @@ module T::Private::Methods
|
|
311
311
|
|
312
312
|
def self.build_sig(hook_mod, method_name, original_method, current_declaration, loc)
|
313
313
|
begin
|
314
|
-
# We allow `sig` in the current module's context (normal case) and
|
315
|
-
if hook_mod != current_declaration.mod &&
|
314
|
+
# We allow `sig` in the current module's context (normal case) and
|
315
|
+
if hook_mod != current_declaration.mod &&
|
316
|
+
# inside `class << self`, and
|
317
|
+
hook_mod.singleton_class != current_declaration.mod &&
|
318
|
+
# on `self` at the top level of a file
|
319
|
+
current_declaration.mod != TOP_SELF
|
316
320
|
raise "A method (#{method_name}) is being added on a different class/module (#{hook_mod}) than the " \
|
317
321
|
"last call to `sig` (#{current_declaration.mod}). Make sure each call " \
|
318
322
|
"to `sig` is immediately followed by a method definition on the same " \
|
@@ -462,6 +466,20 @@ module T::Private::Methods
|
|
462
466
|
return if @installed_hooks.include?(mod)
|
463
467
|
@installed_hooks << mod
|
464
468
|
|
469
|
+
if mod == TOP_SELF
|
470
|
+
# self at the top-level of a file is weirdly special in Ruby
|
471
|
+
# The Ruby VM on startup creates an `Object.new` and stashes it.
|
472
|
+
# Unlike when we're using sig inside a module, `self` is actually a
|
473
|
+
# normal object, not an instance of Module.
|
474
|
+
#
|
475
|
+
# Thus we can't ask things like mod.singleton_class? (since that's
|
476
|
+
# defined only on Module, not on Object) and even if we could, the places
|
477
|
+
# where we need to install the hooks are special.
|
478
|
+
mod.extend(SingletonMethodHooks) # def self.foo; end (at top level)
|
479
|
+
Object.extend(MethodHooks) # def foo; end (at top level)
|
480
|
+
return
|
481
|
+
end
|
482
|
+
|
465
483
|
if mod.singleton_class?
|
466
484
|
mod.include(SingletonMethodHooks)
|
467
485
|
else
|
@@ -485,3 +503,8 @@ module T::Private::Methods
|
|
485
503
|
obj.instance_method(name)
|
486
504
|
end
|
487
505
|
end
|
506
|
+
|
507
|
+
# This has to be here, and can't be nested inside `T::Private::Methods`,
|
508
|
+
# because the value of `self` depends on lexical (nesting) scope, and we
|
509
|
+
# specifically need a reference to the file-level self, i.e. `main:Object`
|
510
|
+
T::Private::Methods::TOP_SELF = self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorbet-runtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5939
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 2.7.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: subprocess
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.5.3
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.5.3
|
139
153
|
description: Sorbet's runtime type checking component
|
140
154
|
email:
|
141
155
|
executables: []
|