sorbet-runtime 0.5.11340 → 0.5.11342
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/configuration.rb +1 -0
- data/lib/types/enum.rb +73 -60
- 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: 6522cc782b755c0b04f4dd47d8487496ecbe90ce8dd4cb9e4b83c3c0c38a95f0
|
|
4
|
+
data.tar.gz: 52b03a1a2924d542a2fdf85094298d3025b3ac636c5d97a34fe818845140b6de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 79ef7f9e7574fd26943ad1a984cc152aadf333c1b95e1b828360cee26130e04bb1cfb9842735078ee8ee96ed8bd97fc15cd0a1580d2dc42e85f9d5ea1a667f95
|
|
7
|
+
data.tar.gz: b7933a4ab92cb3424745776426460a0eaaf48cc6676caf561e498b93bbef77ff03afda36d777ca1ede2b1ffd63f465f0cdf8ca6a9ba99e84f44a7f64f98192aa
|
data/lib/types/configuration.rb
CHANGED
|
@@ -536,6 +536,7 @@ module T::Configuration
|
|
|
536
536
|
|
|
537
537
|
@legacy_t_enum_migration_mode = false
|
|
538
538
|
def self.enable_legacy_t_enum_migration_mode
|
|
539
|
+
T::Enum.include(T::Enum::LegacyMigrationMode)
|
|
539
540
|
@legacy_t_enum_migration_mode = true
|
|
540
541
|
end
|
|
541
542
|
def self.disable_legacy_t_enum_migration_mode
|
data/lib/types/enum.rb
CHANGED
|
@@ -185,77 +185,90 @@ class T::Enum
|
|
|
185
185
|
end
|
|
186
186
|
end
|
|
187
187
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if T::Configuration.legacy_t_enum_migration_mode?
|
|
199
|
-
T::Configuration.soft_assert_handler(
|
|
200
|
-
msg,
|
|
201
|
-
storytime: {
|
|
202
|
-
class: self.class.name,
|
|
203
|
-
caller_location: caller_locations(1..1)&.[](0)&.then {"#{_1.path}:#{_1.lineno}"},
|
|
204
|
-
},
|
|
205
|
-
)
|
|
206
|
-
serialize.to_s
|
|
207
|
-
else
|
|
208
|
-
raise NoMethodError.new(msg)
|
|
188
|
+
module LegacyMigrationMode
|
|
189
|
+
include Kernel
|
|
190
|
+
extend T::Helpers
|
|
191
|
+
abstract!
|
|
192
|
+
|
|
193
|
+
if T.unsafe(false)
|
|
194
|
+
# Declare to the type system that the `serialize` method for sure exists
|
|
195
|
+
# on whatever we mix this into.
|
|
196
|
+
T::Sig::WithoutRuntime.sig {abstract.returns(T.untyped)}
|
|
197
|
+
def serialize; end
|
|
209
198
|
end
|
|
210
|
-
end
|
|
211
199
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
200
|
+
# NB: Do not call this method. This exists to allow for a safe migration path in places where enum
|
|
201
|
+
# values are compared directly against string values.
|
|
202
|
+
#
|
|
203
|
+
# Ruby's string has a weird quirk where `'my_string' == obj` calls obj.==('my_string') if obj
|
|
204
|
+
# responds to the `to_str` method. It does not actually call `to_str` however.
|
|
205
|
+
#
|
|
206
|
+
# See https://ruby-doc.org/core-2.4.0/String.html#method-i-3D-3D
|
|
207
|
+
T::Sig::WithoutRuntime.sig {returns(String)}
|
|
208
|
+
def to_str
|
|
209
|
+
msg = 'Implicit conversion of Enum instances to strings is not allowed. Call #serialize instead.'
|
|
217
210
|
if T::Configuration.legacy_t_enum_migration_mode?
|
|
218
|
-
|
|
219
|
-
|
|
211
|
+
T::Configuration.soft_assert_handler(
|
|
212
|
+
msg,
|
|
213
|
+
storytime: {
|
|
214
|
+
class: self.class.name,
|
|
215
|
+
caller_location: Kernel.caller_locations(1..1)&.[](0)&.then {"#{_1.path}:#{_1.lineno}"},
|
|
216
|
+
},
|
|
217
|
+
)
|
|
218
|
+
serialize.to_s
|
|
220
219
|
else
|
|
221
|
-
|
|
220
|
+
Kernel.raise NoMethodError.new(msg)
|
|
222
221
|
end
|
|
223
|
-
else
|
|
224
|
-
super(other)
|
|
225
222
|
end
|
|
226
|
-
end
|
|
227
223
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
224
|
+
# WithoutRuntime so that comparison_assertion_failed can assume a constant stack depth
|
|
225
|
+
T::Sig::WithoutRuntime.sig {params(other: BasicObject).returns(T::Boolean)}
|
|
226
|
+
def ==(other)
|
|
227
|
+
case other
|
|
228
|
+
when String
|
|
229
|
+
if T::Configuration.legacy_t_enum_migration_mode?
|
|
230
|
+
comparison_assertion_failed(:==, other)
|
|
231
|
+
self.serialize == other
|
|
232
|
+
else
|
|
233
|
+
false
|
|
234
|
+
end
|
|
236
235
|
else
|
|
237
|
-
|
|
236
|
+
super(other)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# WithoutRuntime so that comparison_assertion_failed can assume a constant stack depth
|
|
241
|
+
T::Sig::WithoutRuntime.sig {params(other: BasicObject).returns(T::Boolean)}
|
|
242
|
+
def ===(other)
|
|
243
|
+
case other
|
|
244
|
+
when String
|
|
245
|
+
if T::Configuration.legacy_t_enum_migration_mode?
|
|
246
|
+
comparison_assertion_failed(:===, other)
|
|
247
|
+
self.serialize == other
|
|
248
|
+
else
|
|
249
|
+
false
|
|
250
|
+
end
|
|
251
|
+
else
|
|
252
|
+
super(other)
|
|
238
253
|
end
|
|
239
|
-
else
|
|
240
|
-
super(other)
|
|
241
254
|
end
|
|
242
|
-
end
|
|
243
255
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
# WithoutRuntime so that caller_locations can assume a constant stack depth
|
|
257
|
+
# (Otherwise, the first call would be the method with the wrapping, which would have a different stack depth.)
|
|
258
|
+
T::Sig::WithoutRuntime.sig {params(method: Symbol, other: T.untyped).void}
|
|
259
|
+
private def comparison_assertion_failed(method, other)
|
|
260
|
+
T::Configuration.soft_assert_handler(
|
|
261
|
+
'Enum to string comparison not allowed. Compare to the Enum instance directly instead. See go/enum-migration',
|
|
262
|
+
storytime: {
|
|
263
|
+
class: self.class.name,
|
|
264
|
+
self: self.inspect,
|
|
265
|
+
other: other,
|
|
266
|
+
other_class: other.class.name,
|
|
267
|
+
method: method,
|
|
268
|
+
caller_location: Kernel.caller_locations(2..2)&.[](0)&.then {"#{_1.path}:#{_1.lineno}"},
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
end
|
|
259
272
|
end
|
|
260
273
|
|
|
261
274
|
### Private implementation ###
|
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.11342
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stripe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-04-
|
|
11
|
+
date: 2024-04-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|