sorbet-runtime 0.5.10461 → 0.5.10470

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/types/_types.rb +28 -0
  3. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad78cb1ef08fe9a8f5ac0fe6f69d56ee931dc7768b21761177ea093153a00f7a
4
- data.tar.gz: befebc526f225a590a907eac2b05270c09c62c9be7cd59b3a4a14d8f2fc183ac
3
+ metadata.gz: 379d84e84abe1b5c02ec69fa64d931ad61c1b8d52e9f9fc03dc4123c37f3299f
4
+ data.tar.gz: 3531d39402cd628392b8a17a80c207fcfc0ac3a82c3409e6445da8178fc87fc9
5
5
  SHA512:
6
- metadata.gz: 9aa012c622c636cef39a643ce67d0ab5df6ea20326cdc5564c82ca278407ae629e3b786d46ebaee41e79dc533e92bbe08e3f41c23af0a4e12fcfb097a87df245
7
- data.tar.gz: 52ee3c205e58e786cab5d1eaa7a4f94addce8a29f6822ca133c55fd817b22666d7bfb8d9bd95ff6e8edada7f442aa07100ce6c8edbfd24b448fc5942d4eff38c
6
+ metadata.gz: edd9ae63bc0220474cf4210514ed2563e7b77eab79704a9e845f23d8a1023ae13238159bddba0174de7467f2dffc05757c4c346a0a4fa0fc5605ffb571b78849
7
+ data.tar.gz: bb5e4c7796c5270f49e1b935ae4627c2e6891f2b39eb4adca3421964c8819e7c61e77fa1c2ae590d38810dc5936dd391dce13447565e508ce06179f53167bf65
data/lib/types/_types.rb CHANGED
@@ -221,6 +221,34 @@ module T
221
221
  end
222
222
  end
223
223
 
224
+ # A convenience method to `raise` with a provided error reason when the argument
225
+ # is `nil` and return it otherwise.
226
+ #
227
+ # Intended to be used as:
228
+ #
229
+ # needs_foo(T.must_because(maybe_gives_foo) {"reason_foo_should_not_be_nil"})
230
+ #
231
+ # Equivalent to:
232
+ #
233
+ # foo = maybe_gives_foo
234
+ # raise "reason_foo_should_not_be_nil" if foo.nil?
235
+ # needs_foo(foo)
236
+ #
237
+ # Intended to be used to promise sorbet that a given nilable value happens
238
+ # to contain a non-nil value at this point.
239
+ #
240
+ # `sig {params(arg: T.nilable(A), reason_blk: T.proc.returns(String)).returns(A)}`
241
+ def self.must_because(arg)
242
+ return arg if arg
243
+ return arg if arg == false
244
+
245
+ begin
246
+ raise TypeError.new("Unexpected `nil` because #{yield}")
247
+ rescue TypeError => e # raise into rescue to ensure e.backtrace is populated
248
+ T::Configuration.inline_type_error_handler(e, {kind: 'T.must_because', value: arg, type: nil})
249
+ end
250
+ end
251
+
224
252
  # A way to ask Sorbet to show what type it thinks an expression has.
225
253
  # This can be useful for debugging and checking assumptions.
226
254
  # In the runtime, merely returns the value passed in.
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.10461
4
+ version: 0.5.10470
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-28 00:00:00.000000000 Z
11
+ date: 2022-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: 1.5.3
153
153
  description: Sorbet's runtime type checking component
154
- email:
154
+ email:
155
155
  executables: []
156
156
  extensions: []
157
157
  extra_rdoc_files: []
@@ -245,7 +245,7 @@ licenses:
245
245
  - Apache-2.0
246
246
  metadata:
247
247
  source_code_uri: https://github.com/sorbet/sorbet
248
- post_install_message:
248
+ post_install_message:
249
249
  rdoc_options: []
250
250
  require_paths:
251
251
  - lib
@@ -253,15 +253,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
253
  requirements:
254
254
  - - ">="
255
255
  - !ruby/object:Gem::Version
256
- version: 2.3.0
256
+ version: 2.7.0
257
257
  required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  requirements:
259
259
  - - ">="
260
260
  - !ruby/object:Gem::Version
261
261
  version: '0'
262
262
  requirements: []
263
- rubygems_version: 3.1.4
264
- signing_key:
263
+ rubygems_version: 3.3.7
264
+ signing_key:
265
265
  specification_version: 4
266
266
  summary: Sorbet runtime
267
267
  test_files: []