sorbet-runtime 0.5.5406 → 0.5.5410

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eae0cc4b7fdb52047e84a290e7b7cd213cdc65e695367520f0b6f20812ae2a11
4
- data.tar.gz: 760c82af2b52574b6de71ac9871e34b6086cd0938d285e84840ded2deabf370b
3
+ metadata.gz: 72e771c6dd47d33ac98f5acec99201a8bd2b8dcbe41b8c28101f301c91fd62a2
4
+ data.tar.gz: 4ae0ff258bfd7d346e68766354490a1de8ecd624e61755a442613bff8a7c3548
5
5
  SHA512:
6
- metadata.gz: fe8068bf43f3a19b01697898272ac24fe375a908f72aeeaffc57be2863bfde26ed19f5ce2d9b7da7d2de8d1d4b3f9805685507ef1020035e1f3339a7406407f9
7
- data.tar.gz: 1fe68bcff353ed2ba795b315382fbb3262664c87134f6a68bb34ff6e375c9334efbb4fb20df31677135fd1fc92e8ae2b7210be0bd1f99f2c5eeb70b8fb5d6578
6
+ metadata.gz: 7711cad1c9dda852f2977ed55d85020ede97b6c05a233046a4e4b4d51b9fa3f9813258d1b0aae08cb77a24444f105213ad9818940b521ee829becb9411791607
7
+ data.tar.gz: 885b932a56b3b492ed7dfcad5c530df0530e2d6600c81d8168dbaaef9cab6d9eef3826e3ab96f00cb1fe277a133916e3dbd7c71c23de37ef64afe917694542b6
@@ -67,6 +67,7 @@ class T::Props::Decorator
67
67
  clobber_existing_method!
68
68
  extra
69
69
  optional
70
+ setter_validate
70
71
  _tnilable
71
72
  }.map {|k| [k, true]}.to_h.freeze, T::Hash[Symbol, T::Boolean])
72
73
  private_constant :VALID_RULE_KEYS
@@ -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.5406
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-02-29 00:00:00.000000000 Z
11
+ date: 2020-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest