sorbet-runtime 0.5.10148 → 0.5.10154

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/struct.rb +33 -0
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e926af9ec9d3dc5ecd153d92be573ded3e2f622123a0e899bc43248aede07f4
4
- data.tar.gz: 4469a42ab97d71a001376bb5126f52461a7bcba7aae41151bcdea0ec53c4057f
3
+ metadata.gz: d7a443545675cd9f8069f7fc672324139a9a94f9854b0f9330cbf832bf1b153c
4
+ data.tar.gz: fa4123846ae5706f7aaf95cde98aa2dfa14c90d6906c0ee4366b3f4994c5567a
5
5
  SHA512:
6
- metadata.gz: 56dfaffe65419e89c99c7297e4001999b5fe847f1856978324820439cb2cef1a51e7c8f0d176266eb935b33f54b9f6b0bd257c18c98409642adee96658fb6940
7
- data.tar.gz: 50a60ea9ce7226f962f8ce583e98d099a1b63b764cf3c2ba057a3e1adfe27aa0fbd0883f6904d0abc31ce237ac79274396d4a10a666ade7ccc30b105861aafeb
6
+ metadata.gz: 4c1060562e6f4af2c20d0af9adc4f38d7818426e75fc3a5971bb0f8e4822820765250ff938253e832dd073445043d9ec069fbb24dd7d5e4eb49d79cbfacf7401
7
+ data.tar.gz: 5b835a51c09600e451dc79dae53c73a4c2a6a78c622375c9d92abc0843bc57960bdc36794f1819f16d36324825bcfe209843f7f7eccc6137c4d69ab761427b22
data/lib/types/struct.rb CHANGED
@@ -16,3 +16,36 @@ class T::Struct < T::InexactStruct
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ class T::ImmutableStruct < T::InexactStruct
21
+ extend T::Sig
22
+
23
+ def self.inherited(subclass)
24
+ super(subclass)
25
+
26
+ T::Private::ClassUtils.replace_method(subclass.singleton_class, :inherited) do |s|
27
+ super(s)
28
+ raise "#{self.name} is a subclass of T::ImmutableStruct and cannot be subclassed"
29
+ end
30
+ end
31
+
32
+ # Matches the one in WeakConstructor, but freezes the object
33
+ sig {params(hash: T::Hash[Symbol, T.untyped]).void.checked(:never)}
34
+ def initialize(hash={})
35
+ super
36
+
37
+ freeze
38
+ end
39
+
40
+ # Matches the signature in Props, but raises since this is an immutable struct and only const is allowed
41
+ sig {params(name: Symbol, cls: T.untyped, rules: T.untyped).void}
42
+ def self.prop(name, cls, rules={})
43
+ return super if (cls.is_a?(Hash) && cls[:immutable]) || rules[:immutable]
44
+
45
+ raise "Cannot use `prop` in #{self.name} because it is an immutable struct. Use `const` instead"
46
+ end
47
+
48
+ def with(changed_props)
49
+ raise "Cannot use `with` in #{self.class.name} because it is an immutable struct"
50
+ end
51
+ end
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.10148
4
+ version: 0.5.10154
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-08 00:00:00.000000000 Z
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest