sorbet-runtime 0.5.10151 → 0.5.10158

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: 7d6b316fa0e57d59e89a9735ada8dac0413dd6330eedb49aadc715ca6c3e3354
4
- data.tar.gz: 53fc87ab75ea0f32dff7b765901f858bc41797f2e4f728402f59dd0df9ce9715
3
+ metadata.gz: 82f3d3e511c18b59ec44d0a3951ec907d9f6c7d0ce512532fcdb497eda9a0ae2
4
+ data.tar.gz: 7231aa5c26aeb812e410d98c91df68868ccb193c3eb4bc926904889292b71844
5
5
  SHA512:
6
- metadata.gz: 5310e4e6d1762462009afb71be1f55206753ea6a317b9eabf6eab7a48612527f9c33f5f72ad7ce22352eb94463554b065b9773fb70b24e26236af5ff5a4fef21
7
- data.tar.gz: 7f5f99c92cdc1d7b59464c19a3f07f8b72393535d7b5aeb2a594d9a6eae05192c8453b11791b8615a68b14316c708d0151e9c971b5b77426dcb5abb7ab8ef472
6
+ metadata.gz: dd872acad7c1c2b02805133d9662be40a9084cc8c4445b7f874a978f7f02142310a2bd0bba25fe98dcca1fc1365a5182bb31e1c78f386c73d20d6918fb686e6d
7
+ data.tar.gz: 05a95727afcc2fdf648799404ee015e6a672deb86c4598ee531f5bdcd2c1dc7cc6699ff6e2aa848a7412a1e04c556aeef9ce6f37b2ad30bc98503d65b7a02b57
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.10151
4
+ version: 0.5.10158
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-09 00:00:00.000000000 Z
11
+ date: 2022-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest