sorbet-runtime 0.5.5406 → 0.5.5410
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/types/props/decorator.rb +1 -0
- data/lib/types/props/private/setter_factory.rb +14 -4
- 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: 72e771c6dd47d33ac98f5acec99201a8bd2b8dcbe41b8c28101f301c91fd62a2
|
|
4
|
+
data.tar.gz: 4ae0ff258bfd7d346e68766354490a1de8ecd624e61755a442613bff8a7c3548
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7711cad1c9dda852f2977ed55d85020ede97b6c05a233046a4e4b4d51b9fa3f9813258d1b0aae08cb77a24444f105213ad9818940b521ee829becb9411791607
|
|
7
|
+
data.tar.gz: 885b932a56b3b492ed7dfcad5c530df0530e2d6600c81d8168dbaaef9cab6d9eef3826e3ab96f00cb1fe277a133916e3dbd7c71c23de37ef64afe917694542b6
|
|
@@ -7,6 +7,7 @@ module T::Props
|
|
|
7
7
|
extend T::Sig
|
|
8
8
|
|
|
9
9
|
SetterProc = T.type_alias {T.proc.params(val: T.untyped).void}
|
|
10
|
+
ValidateProc = T.type_alias {T.proc.params(prop: Symbol, value: T.untyped).void}
|
|
10
11
|
|
|
11
12
|
sig do
|
|
12
13
|
params(
|
|
@@ -31,6 +32,7 @@ module T::Props
|
|
|
31
32
|
T::Utils::Nilable.get_underlying_type_object(rules.fetch(:type_object))
|
|
32
33
|
end
|
|
33
34
|
accessor_key = rules.fetch(:accessor_key)
|
|
35
|
+
validate = rules[:setter_validate]
|
|
34
36
|
|
|
35
37
|
# It seems like a bug that this affects the behavior of setters, but
|
|
36
38
|
# some existing code relies on this behavior
|
|
@@ -39,9 +41,9 @@ module T::Props
|
|
|
39
41
|
# Use separate methods in order to ensure that we only close over necessary
|
|
40
42
|
# variables
|
|
41
43
|
if !T::Props::Utils.need_nil_write_check?(rules) || has_explicit_nil_default
|
|
42
|
-
nilable_proc(prop, accessor_key, non_nil_type, klass)
|
|
44
|
+
nilable_proc(prop, accessor_key, non_nil_type, klass, validate)
|
|
43
45
|
else
|
|
44
|
-
non_nil_proc(prop, accessor_key, non_nil_type, klass)
|
|
46
|
+
non_nil_proc(prop, accessor_key, non_nil_type, klass, validate)
|
|
45
47
|
end
|
|
46
48
|
end
|
|
47
49
|
|
|
@@ -51,12 +53,16 @@ module T::Props
|
|
|
51
53
|
accessor_key: Symbol,
|
|
52
54
|
non_nil_type: T.any(T::Types::Base, T.all(T::Props::CustomType, Module)),
|
|
53
55
|
klass: T.all(Module, T::Props::ClassMethods),
|
|
56
|
+
validate: T.nilable(ValidateProc)
|
|
54
57
|
)
|
|
55
58
|
.returns(SetterProc)
|
|
56
59
|
end
|
|
57
|
-
private_class_method def self.non_nil_proc(prop, accessor_key, non_nil_type, klass)
|
|
60
|
+
private_class_method def self.non_nil_proc(prop, accessor_key, non_nil_type, klass, validate)
|
|
58
61
|
proc do |val|
|
|
59
62
|
if non_nil_type.valid?(val)
|
|
63
|
+
if validate
|
|
64
|
+
validate.call(prop, val)
|
|
65
|
+
end
|
|
60
66
|
instance_variable_set(accessor_key, val)
|
|
61
67
|
else
|
|
62
68
|
T::Props::Private::SetterFactory.raise_pretty_error(
|
|
@@ -75,14 +81,18 @@ module T::Props
|
|
|
75
81
|
accessor_key: Symbol,
|
|
76
82
|
non_nil_type: T.any(T::Types::Base, T.all(T::Props::CustomType, Module)),
|
|
77
83
|
klass: T.all(Module, T::Props::ClassMethods),
|
|
84
|
+
validate: T.nilable(ValidateProc),
|
|
78
85
|
)
|
|
79
86
|
.returns(SetterProc)
|
|
80
87
|
end
|
|
81
|
-
private_class_method def self.nilable_proc(prop, accessor_key, non_nil_type, klass)
|
|
88
|
+
private_class_method def self.nilable_proc(prop, accessor_key, non_nil_type, klass, validate)
|
|
82
89
|
proc do |val|
|
|
83
90
|
if val.nil?
|
|
84
91
|
instance_variable_set(accessor_key, nil)
|
|
85
92
|
elsif non_nil_type.valid?(val)
|
|
93
|
+
if validate
|
|
94
|
+
validate.call(prop, val)
|
|
95
|
+
end
|
|
86
96
|
instance_variable_set(accessor_key, val)
|
|
87
97
|
else
|
|
88
98
|
T::Props::Private::SetterFactory.raise_pretty_error(
|
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.5410
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stripe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-03-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|