sorbet-runtime 0.5.5400 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4f9fd0690e5e4161f08d170c0ad34c991b419d7718cb6d3cc3db90036c35387
4
- data.tar.gz: acd9cfcc9cca1df5271b927d2dd85ffa0276337276a0df1ee522fe0c55dde9a4
3
+ metadata.gz: 72e771c6dd47d33ac98f5acec99201a8bd2b8dcbe41b8c28101f301c91fd62a2
4
+ data.tar.gz: 4ae0ff258bfd7d346e68766354490a1de8ecd624e61755a442613bff8a7c3548
5
5
  SHA512:
6
- metadata.gz: c9935807087e676840c09e8e2c43b4c3bc25639264bb8ed793a0e677fce16742db55a14362a39e701da6e63b130ffa1213717e755a98695db849dc1c5ba9dcd5
7
- data.tar.gz: b0ee575a179bb1a6da3a10d3f40a16e27a94f739c28ca47bd174b9f7c854d90e5a5085bea444d715f1dc4fa12ffef98cdc98166c2af962ac06c5ff27dce0f911
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
@@ -429,7 +430,7 @@ class T::Props::Decorator
429
430
  end
430
431
 
431
432
  handle_foreign_option(name, cls, rules, rules[:foreign]) if rules[:foreign]
432
- handle_foreign_hint_only_option(cls, rules[:foreign_hint_only]) if rules[:foreign_hint_only]
433
+ handle_foreign_hint_only_option(name, cls, rules[:foreign_hint_only]) if rules[:foreign_hint_only]
433
434
  handle_redaction_option(name, rules[:redaction]) if rules[:redaction]
434
435
  end
435
436
 
@@ -636,12 +637,13 @@ class T::Props::Decorator
636
637
 
637
638
  sig do
638
639
  params(
640
+ prop_name: Symbol,
639
641
  prop_cls: Module,
640
642
  foreign_hint_only: T.untyped,
641
643
  )
642
644
  .void
643
645
  end
644
- private def handle_foreign_hint_only_option(prop_cls, foreign_hint_only)
646
+ private def handle_foreign_hint_only_option(prop_name, prop_cls, foreign_hint_only)
645
647
  if ![String, Array].include?(prop_cls) && !(prop_cls.is_a?(T::Props::CustomType))
646
648
  raise ArgumentError.new(
647
649
  "`foreign_hint_only` can only be used with String or Array prop types"
@@ -652,6 +654,21 @@ class T::Props::Decorator
652
654
  :foreign_hint_only, foreign_hint_only,
653
655
  valid_type_msg: "an individual or array of a model class, or a Proc returning such."
654
656
  )
657
+
658
+ unless foreign_hint_only.is_a?(Proc)
659
+ T::Configuration.soft_assert_handler(<<~MESSAGE, storytime: {prop: prop_name, value: foreign_hint_only}, notify: 'jerry')
660
+ Please use a Proc that returns a model class instead of the model class itself as the argument to `foreign_hint_only`. In other words:
661
+
662
+ instead of `prop :foo, String, foreign_hint_only: FooModel`
663
+ use `prop :foo, String, foreign_hint_only: -> {FooModel}`
664
+
665
+ OR
666
+
667
+ instead of `prop :foo, String, foreign_hint_only: [FooModel, BarModel]`
668
+ use `prop :foo, String, foreign_hint_only: -> {[FooModel, BarModel]}`
669
+
670
+ MESSAGE
671
+ end
655
672
  end
656
673
 
657
674
  # checked(:never) - Rules hash is expensive to check
@@ -745,6 +762,16 @@ class T::Props::Decorator
745
762
  )
746
763
  end
747
764
 
765
+ unless foreign.is_a?(Proc)
766
+ T::Configuration.soft_assert_handler(<<~MESSAGE, storytime: {prop: prop_name, value: foreign}, notify: 'jerry')
767
+ Please use a Proc that returns a model class instead of the model class itself as the argument to `foreign`. In other words:
768
+
769
+ instead of `prop :foo, String, foreign: FooModel`
770
+ use `prop :foo, String, foreign: -> {FooModel}`
771
+
772
+ MESSAGE
773
+ end
774
+
748
775
  define_foreign_method(prop_name, rules, foreign)
749
776
  end
750
777
 
@@ -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)
44
+ nilable_proc(prop, accessor_key, non_nil_type, klass, validate)
43
45
  else
44
- non_nil_proc(prop, accessor_key, non_nil_type)
46
+ non_nil_proc(prop, accessor_key, non_nil_type, klass, validate)
45
47
  end
46
48
  end
47
49
 
@@ -50,16 +52,21 @@ module T::Props
50
52
  prop: Symbol,
51
53
  accessor_key: Symbol,
52
54
  non_nil_type: T.any(T::Types::Base, T.all(T::Props::CustomType, Module)),
55
+ klass: T.all(Module, T::Props::ClassMethods),
56
+ validate: T.nilable(ValidateProc)
53
57
  )
54
58
  .returns(SetterProc)
55
59
  end
56
- private_class_method def self.non_nil_proc(prop, accessor_key, non_nil_type)
60
+ private_class_method def self.non_nil_proc(prop, accessor_key, non_nil_type, klass, validate)
57
61
  proc do |val|
58
62
  if non_nil_type.valid?(val)
63
+ if validate
64
+ validate.call(prop, val)
65
+ end
59
66
  instance_variable_set(accessor_key, val)
60
67
  else
61
68
  T::Props::Private::SetterFactory.raise_pretty_error(
62
- T.unsafe(self.class),
69
+ klass,
63
70
  prop,
64
71
  non_nil_type,
65
72
  val,
@@ -73,18 +80,23 @@ module T::Props
73
80
  prop: Symbol,
74
81
  accessor_key: Symbol,
75
82
  non_nil_type: T.any(T::Types::Base, T.all(T::Props::CustomType, Module)),
83
+ klass: T.all(Module, T::Props::ClassMethods),
84
+ validate: T.nilable(ValidateProc),
76
85
  )
77
86
  .returns(SetterProc)
78
87
  end
79
- private_class_method def self.nilable_proc(prop, accessor_key, non_nil_type)
88
+ private_class_method def self.nilable_proc(prop, accessor_key, non_nil_type, klass, validate)
80
89
  proc do |val|
81
90
  if val.nil?
82
91
  instance_variable_set(accessor_key, nil)
83
92
  elsif non_nil_type.valid?(val)
93
+ if validate
94
+ validate.call(prop, val)
95
+ end
84
96
  instance_variable_set(accessor_key, val)
85
97
  else
86
98
  T::Props::Private::SetterFactory.raise_pretty_error(
87
- T.unsafe(self.class),
99
+ klass,
88
100
  prop,
89
101
  non_nil_type,
90
102
  val,
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.5400
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-26 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