sorbet-runtime 0.5.6514 → 0.5.6530

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: 2af30719f7576613c6f9bbca18baf2b1a9c656326f33e2500162b5f64212ba25
4
- data.tar.gz: 3779ac3fb8379a7cb990ac1422ebf8685dd8806d6b272e6cbd10b1f348ccab3e
3
+ metadata.gz: c03e969e1e5d1c7e51337b3aa6b4510f5ea9d6e5cee0ef5ff9a688f3cd7e6691
4
+ data.tar.gz: 0e40340472be212625d26767a063281692837d422fedeaba8c4f60836955ca97
5
5
  SHA512:
6
- metadata.gz: 11bde32f8368f6a707d0c72520a35e7e71850e3488bbe8979844a49934a5f50082346c2a8042568616e9570db648acef6a19ea143ced60170ba01849d8972417
7
- data.tar.gz: 452d43a169e2af103335782e98a6f7dc3dec71c59205f2583c91e559c491c59d642f4ce9df003c53c7de70fcb29c9ac77efb45aba22f66d303c8d30bcb11fca5
6
+ metadata.gz: f1b67df79e4b83be9522ab9ca9862db428a9fa97809513897cf68c06fa35c98a6e4024b5f16634c27a0b9516a13b56763a43526a0c3715572612ddb39384ba70
7
+ data.tar.gz: 1a1f952f9df8a9b7fc5f0ea5a72fb081f647eff64e919e4c1bbc75a07aa3b0030c4a6856e0cfe89ca9b9d5be12d2becb05b6cb9e4cd55a2583b512643e9c6e26
data/lib/types/generic.rb CHANGED
@@ -2,7 +2,6 @@
2
2
  # typed: true
3
3
 
4
4
  # Use as a mixin with extend (`extend T::Generic`).
5
- # Docs at https://hackpad.corp.stripe.com/Type-Validation-in-pay-server-1JaoTHir5Mo.
6
5
  module T::Generic
7
6
  include T::Helpers
8
7
  include Kernel
@@ -34,9 +34,40 @@ module T::Props
34
34
  # Use separate methods in order to ensure that we only close over necessary
35
35
  # variables
36
36
  if !T::Props::Utils.need_nil_write_check?(rules) || has_explicit_nil_default
37
- nilable_proc(prop, accessor_key, non_nil_type, klass, validate)
37
+ if validate.nil? && non_nil_type.is_a?(T::Types::Simple)
38
+ simple_nilable_proc(prop, accessor_key, non_nil_type.raw_type, klass)
39
+ else
40
+ nilable_proc(prop, accessor_key, non_nil_type, klass, validate)
41
+ end
38
42
  else
39
- non_nil_proc(prop, accessor_key, non_nil_type, klass, validate)
43
+ if validate.nil? && non_nil_type.is_a?(T::Types::Simple)
44
+ simple_non_nil_proc(prop, accessor_key, non_nil_type.raw_type, klass)
45
+ else
46
+ non_nil_proc(prop, accessor_key, non_nil_type, klass, validate)
47
+ end
48
+ end
49
+ end
50
+
51
+ sig do
52
+ params(
53
+ prop: Symbol,
54
+ accessor_key: Symbol,
55
+ non_nil_type: Module,
56
+ klass: T.all(Module, T::Props::ClassMethods),
57
+ )
58
+ .returns(SetterProc)
59
+ end
60
+ private_class_method def self.simple_non_nil_proc(prop, accessor_key, non_nil_type, klass)
61
+ proc do |val|
62
+ unless val.is_a?(non_nil_type)
63
+ T::Props::Private::SetterFactory.raise_pretty_error(
64
+ klass,
65
+ prop,
66
+ T::Utils.coerce(non_nil_type),
67
+ val,
68
+ )
69
+ end
70
+ instance_variable_set(accessor_key, val)
40
71
  end
41
72
  end
42
73
 
@@ -71,6 +102,33 @@ module T::Props
71
102
  end
72
103
  end
73
104
 
105
+ sig do
106
+ params(
107
+ prop: Symbol,
108
+ accessor_key: Symbol,
109
+ non_nil_type: Module,
110
+ klass: T.all(Module, T::Props::ClassMethods),
111
+ )
112
+ .returns(SetterProc)
113
+ end
114
+ private_class_method def self.simple_nilable_proc(prop, accessor_key, non_nil_type, klass)
115
+ proc do |val|
116
+ if val.nil?
117
+ instance_variable_set(accessor_key, nil)
118
+ elsif val.is_a?(non_nil_type)
119
+ instance_variable_set(accessor_key, val)
120
+ else
121
+ T::Props::Private::SetterFactory.raise_pretty_error(
122
+ klass,
123
+ prop,
124
+ T::Utils.coerce(non_nil_type),
125
+ val,
126
+ )
127
+ instance_variable_set(accessor_key, val)
128
+ end
129
+ end
130
+ end
131
+
74
132
  sig do
75
133
  params(
76
134
  prop: Symbol,
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.6514
4
+ version: 0.5.6530
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-22 00:00:00.000000000 Z
11
+ date: 2021-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest