sorbet-runtime 0.5.5390 → 0.5.5391
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/types/props/private/setter_factory.rb +52 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5bde0c41c5f150c9ffffdbd9932cf1e8eb1968c349ef8b5698462c30e2c8130
|
4
|
+
data.tar.gz: e0b3af80d1fa7e9fe41ffd127d840c6bbab035e2b520ca9efa8095252e73762f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfb809867db3ba5bb29f457b7bcba08ef9ab6130ed55855947df6dc7cf35741be95b1ebba221b031e4a70c3f8ad2209daf14bf915c6112a1378c111d2a4ee6f9
|
7
|
+
data.tar.gz: 480080a01f4be2b63b1c711fb1db44f56db5572353ca8853b5f50c0a2c235b89a506209ea2b81c6f48dd2f4003e55e13bd54685faac831426dd90d5f034ee154
|
@@ -31,29 +31,64 @@ module T::Props
|
|
31
31
|
T::Utils::Nilable.get_underlying_type_object(rules.fetch(:type_object))
|
32
32
|
end
|
33
33
|
accessor_key = rules.fetch(:accessor_key)
|
34
|
-
raise_error = ->(val) {raise_pretty_error(klass, prop, non_nil_type, val)}
|
35
34
|
|
36
35
|
# It seems like a bug that this affects the behavior of setters, but
|
37
36
|
# some existing code relies on this behavior
|
38
37
|
has_explicit_nil_default = rules.key?(:default) && rules.fetch(:default).nil?
|
39
38
|
|
39
|
+
# Use separate methods in order to ensure that we only close over necessary
|
40
|
+
# variables
|
40
41
|
if !T::Props::Utils.need_nil_write_check?(rules) || has_explicit_nil_default
|
41
|
-
|
42
|
-
if val.nil?
|
43
|
-
instance_variable_set(accessor_key, nil)
|
44
|
-
elsif non_nil_type.valid?(val)
|
45
|
-
instance_variable_set(accessor_key, val)
|
46
|
-
else
|
47
|
-
raise_error.call(val)
|
48
|
-
end
|
49
|
-
end
|
42
|
+
nilable_proc(prop, accessor_key, non_nil_type)
|
50
43
|
else
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
44
|
+
non_nil_proc(prop, accessor_key, non_nil_type)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
sig do
|
49
|
+
params(
|
50
|
+
prop: Symbol,
|
51
|
+
accessor_key: Symbol,
|
52
|
+
non_nil_type: T.any(T::Types::Base, T.all(T::Props::CustomType, Module)),
|
53
|
+
)
|
54
|
+
.returns(SetterProc)
|
55
|
+
end
|
56
|
+
private_class_method def self.non_nil_proc(prop, accessor_key, non_nil_type)
|
57
|
+
proc do |val|
|
58
|
+
if non_nil_type.valid?(val)
|
59
|
+
instance_variable_set(accessor_key, val)
|
60
|
+
else
|
61
|
+
T::Props::Private::SetterFactory.raise_pretty_error(
|
62
|
+
T.unsafe(self.class),
|
63
|
+
prop,
|
64
|
+
non_nil_type,
|
65
|
+
val,
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
sig do
|
72
|
+
params(
|
73
|
+
prop: Symbol,
|
74
|
+
accessor_key: Symbol,
|
75
|
+
non_nil_type: T.any(T::Types::Base, T.all(T::Props::CustomType, Module)),
|
76
|
+
)
|
77
|
+
.returns(SetterProc)
|
78
|
+
end
|
79
|
+
private_class_method def self.nilable_proc(prop, accessor_key, non_nil_type)
|
80
|
+
proc do |val|
|
81
|
+
if val.nil?
|
82
|
+
instance_variable_set(accessor_key, nil)
|
83
|
+
elsif non_nil_type.valid?(val)
|
84
|
+
instance_variable_set(accessor_key, val)
|
85
|
+
else
|
86
|
+
T::Props::Private::SetterFactory.raise_pretty_error(
|
87
|
+
T.unsafe(self.class),
|
88
|
+
prop,
|
89
|
+
non_nil_type,
|
90
|
+
val,
|
91
|
+
)
|
57
92
|
end
|
58
93
|
end
|
59
94
|
end
|
@@ -67,7 +102,7 @@ module T::Props
|
|
67
102
|
)
|
68
103
|
.void
|
69
104
|
end
|
70
|
-
|
105
|
+
def self.raise_pretty_error(klass, prop, type, val)
|
71
106
|
base_message = "Can't set #{klass.name}.#{prop} to #{val.inspect} (instance of #{val.class}) - need a #{type}"
|
72
107
|
|
73
108
|
pretty_message = "Parameter '#{prop}': #{base_message}\n"
|
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.5391
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|