sorbet-runtime 0.5.10152 → 0.5.10160

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: 45be788ace7c14dd772e993ae6111aa7aaa2a36ed378f817e2bd882a208bfb88
4
- data.tar.gz: 4098e4f276374b4819e22b7f507d8eb77f64fd52c6443fa6888b4c1e76f3bd4c
3
+ metadata.gz: 149fb69f7835367a702d800d06144637bd0689034b04970c2c7a185b9677faef
4
+ data.tar.gz: c3c9eba191075f461d8c6550674ed06342162b81ac1f837932d546d1ec447718
5
5
  SHA512:
6
- metadata.gz: bb02b5ff161949c15229f3a1977b5fd1b77966272d5c98a0678905f95917a8a863b45472a38f7e199e8efcf3cb7f5ea84479170ee23cd37a881e85c5006a52cf
7
- data.tar.gz: 0a2efb385448828d53d54d4c1594d115023406350ef163685e853a00e8c5720f2c7b9f74cd3caf5d989d090e26f1d4b5d11f20b271f1b7e837f5761b4a07e71a
6
+ metadata.gz: 422d81773c07888836fe23580b3831d27e100380ef622540cb9ab75f6f752a55044272210641f1c5e7ee368614815ec551f3502effe88c6ef7230a1682beceff
7
+ data.tar.gz: 1755d05b31492661fcbdea1c01171b09527e67ce789b6b736d83d2627b26d6b3cf012d003962e46dd6c59fe824a199b93094a22d385bf9b5a6f26414a0c74ac3
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.10152
4
+ version: 0.5.10160
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-12 00:00:00.000000000 Z
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest