sorbet-runtime 0.5.11340 → 0.5.11342

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: 7efcefd36fad1216671b366cbda430fd05f98acb93974e2d6103de90aabe0378
4
- data.tar.gz: c0c87ee710c2f7ddaca5b38b20eb7cb1aa0d0cf30e1190b5503de69c861e3d43
3
+ metadata.gz: 6522cc782b755c0b04f4dd47d8487496ecbe90ce8dd4cb9e4b83c3c0c38a95f0
4
+ data.tar.gz: 52b03a1a2924d542a2fdf85094298d3025b3ac636c5d97a34fe818845140b6de
5
5
  SHA512:
6
- metadata.gz: db71360161cbb509cfd1552b8edd3be69754f4fd0019707a7d40e9926666155c0d9f44189c4ffbaa94ce19966d3d78b4690445695129b014a86b2d035d2a6739
7
- data.tar.gz: b5e185e00d19bfe4d51137ae162f0171849a81811ec8f2833b1de0345ffb6aaaac798b8c1c50cc0432052a78d518b7525d5368569f22b77964dfbd25747f20c3
6
+ metadata.gz: 79ef7f9e7574fd26943ad1a984cc152aadf333c1b95e1b828360cee26130e04bb1cfb9842735078ee8ee96ed8bd97fc15cd0a1580d2dc42e85f9d5ea1a667f95
7
+ data.tar.gz: b7933a4ab92cb3424745776426460a0eaaf48cc6676caf561e498b93bbef77ff03afda36d777ca1ede2b1ffd63f465f0cdf8ca6a9ba99e84f44a7f64f98192aa
@@ -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
- # NB: Do not call this method. This exists to allow for a safe migration path in places where enum
189
- # values are compared directly against string values.
190
- #
191
- # Ruby's string has a weird quirk where `'my_string' == obj` calls obj.==('my_string') if obj
192
- # responds to the `to_str` method. It does not actually call `to_str` however.
193
- #
194
- # See https://ruby-doc.org/core-2.4.0/String.html#method-i-3D-3D
195
- T::Sig::WithoutRuntime.sig {returns(String)}
196
- def to_str
197
- msg = 'Implicit conversion of Enum instances to strings is not allowed. Call #serialize instead.'
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
- # WithoutRuntime so that comparison_assertion_failed can assume a constant stack depth
213
- T::Sig::WithoutRuntime.sig {params(other: BasicObject).returns(T::Boolean)}
214
- def ==(other)
215
- case other
216
- when String
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
- comparison_assertion_failed(:==, other)
219
- self.serialize == other
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
- false
220
+ Kernel.raise NoMethodError.new(msg)
222
221
  end
223
- else
224
- super(other)
225
222
  end
226
- end
227
223
 
228
- # WithoutRuntime so that comparison_assertion_failed can assume a constant stack depth
229
- T::Sig::WithoutRuntime.sig {params(other: BasicObject).returns(T::Boolean)}
230
- def ===(other)
231
- case other
232
- when String
233
- if T::Configuration.legacy_t_enum_migration_mode?
234
- comparison_assertion_failed(:===, other)
235
- self.serialize == other
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
- false
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
- # WithoutRuntime so that caller_locations can assume a constant stack depth
245
- # (Otherwise, the first call would be the method with the wrapping, which would have a different stack depth.)
246
- T::Sig::WithoutRuntime.sig {params(method: Symbol, other: T.untyped).void}
247
- private def comparison_assertion_failed(method, other)
248
- T::Configuration.soft_assert_handler(
249
- 'Enum to string comparison not allowed. Compare to the Enum instance directly instead. See go/enum-migration',
250
- storytime: {
251
- class: self.class.name,
252
- self: self.inspect,
253
- other: other,
254
- other_class: other.class.name,
255
- method: method,
256
- caller_location: caller_locations(2..2)&.[](0)&.then {"#{_1.path}:#{_1.lineno}"},
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.11340
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 00:00:00.000000000 Z
11
+ date: 2024-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest