tapioca 0.8.0 → 0.8.1

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: 69afa82ceccd1bd2fa9da5483011763edf2d1913d508a955a3c0b9c91fa2d04a
4
- data.tar.gz: b59721eb57b52b5be09ddfa443eaae90f0b74b6985506da7240159a4c34a21dd
3
+ metadata.gz: a98ca6b703be34409d122ea825e0cd55079669bc86eac3e0d13f201a6ee5059e
4
+ data.tar.gz: 49c8800b44a551fc3f9222fd103fb3a39011927bf25b48e43c9ef998096eabba
5
5
  SHA512:
6
- metadata.gz: 536a4d8e3c9b910f14e3808de67020c0dace80354d86a938a415f503fbc49acec859b3d95a1b6d8fbf3ea0f3be925a5ecfd1c071520eb158abda0ffd61e5ad30
7
- data.tar.gz: 7a43d61449279be2b77fb48e893452eb9a3086c9819fe0d6f75177e1bb8cc1c60748dc0696dcf97641ada93621be760815f356cb979eca771810b07835e0fcef
6
+ metadata.gz: d4d5540ba0d519f224edb20c52c268e64962e343b2d8cba8b0ed1d855270c249b4b71cdffcd30aebafba994bea42e2ac567fafa4b42e6154a1fc67f6cab37825
7
+ data.tar.gz: 22edc86401311b86a3791076d9fd9f7c463c37166e0383987407cdec555c4829ce6a72b899cccb9690d82e3cf96fd366f91926adde90012ddaf38acdb8a8d3ba
@@ -21,47 +21,33 @@ module T
21
21
  Tapioca::Runtime::GenericTypeRegistry.register_type(constant, types)
22
22
  end
23
23
 
24
- def type_member(variance = :invariant, fixed: nil, lower: nil, upper: nil, &blk)
24
+ def type_member(variance = :invariant, fixed: nil, lower: nil, upper: nil, &bounds_proc)
25
25
  # `T::Generic#type_member` just instantiates a `T::Type::TypeMember` instance and returns it.
26
26
  # We use that when registering the type member and then later return it from this method.
27
- hash = if blk
28
- blk.call
29
- else
30
- {
31
- fixed: fixed,
32
- lower: lower,
33
- upper: upper,
34
- }
35
- end
36
-
37
27
  Tapioca::TypeVariableModule.new(
38
28
  T.cast(self, Module),
39
29
  Tapioca::TypeVariableModule::Type::Member,
40
30
  variance,
41
- **hash,
31
+ fixed,
32
+ lower,
33
+ upper,
34
+ bounds_proc
42
35
  ).tap do |type_variable|
43
36
  Tapioca::Runtime::GenericTypeRegistry.register_type_variable(self, type_variable)
44
37
  end
45
38
  end
46
39
 
47
- def type_template(variance = :invariant, fixed: nil, lower: nil, upper: nil, &blk)
40
+ def type_template(variance = :invariant, fixed: nil, lower: nil, upper: nil, &bounds_proc)
48
41
  # `T::Generic#type_template` just instantiates a `T::Type::TypeTemplate` instance and returns it.
49
42
  # We use that when registering the type template and then later return it from this method.
50
- hash = if blk
51
- blk.call
52
- else
53
- {
54
- fixed: fixed,
55
- lower: lower,
56
- upper: upper,
57
- }
58
- end
59
-
60
43
  Tapioca::TypeVariableModule.new(
61
44
  T.cast(self, Module),
62
45
  Tapioca::TypeVariableModule::Type::Template,
63
46
  variance,
64
- **hash,
47
+ fixed,
48
+ lower,
49
+ upper,
50
+ bounds_proc
65
51
  ).tap do |type_variable|
66
52
  Tapioca::Runtime::GenericTypeRegistry.register_type_variable(self, type_variable)
67
53
  end
@@ -136,18 +122,31 @@ module Tapioca
136
122
  end
137
123
  end
138
124
 
125
+ # rubocop:disable Metrics/ParameterLists
139
126
  sig do
140
- params(context: Module, type: Type, variance: Symbol, fixed: T.untyped, lower: T.untyped, upper: T.untyped).void
127
+ params(
128
+ context: Module,
129
+ type: Type,
130
+ variance: Symbol,
131
+ fixed: T.untyped,
132
+ lower: T.untyped,
133
+ upper: T.untyped,
134
+ bounds_proc: T.nilable(T.proc.returns(T::Hash[Symbol, T.untyped]))
135
+ ).void
141
136
  end
142
- def initialize(context, type, variance, fixed: nil, lower: nil, upper: nil)
137
+ def initialize(context, type, variance, fixed, lower, upper, bounds_proc)
143
138
  @context = context
144
139
  @type = type
145
140
  @variance = variance
146
- @fixed = fixed
147
- @lower = lower
148
- @upper = upper
141
+ @bounds_proc = if bounds_proc
142
+ bounds_proc
143
+ else
144
+ build_bounds_proc(fixed, lower, upper)
145
+ end
146
+
149
147
  super()
150
148
  end
149
+ # rubocop:enable Metrics/ParameterLists
151
150
 
152
151
  sig { returns(T.nilable(String)) }
153
152
  def name
@@ -170,9 +169,10 @@ module Tapioca
170
169
 
171
170
  sig { returns(String) }
172
171
  def serialize
173
- fixed = @fixed.to_s if @fixed
174
- upper = @upper.to_s if @upper
175
- lower = @lower.to_s if @lower
172
+ bounds = @bounds_proc.call
173
+ fixed = bounds[:fixed].to_s if bounds.key?(:fixed)
174
+ lower = bounds[:lower].to_s if bounds.key?(:lower)
175
+ upper = bounds[:upper].to_s if bounds.key?(:upper)
176
176
 
177
177
  TypeVariableHelper.serialize_type_variable(
178
178
  @type.serialize,
@@ -190,6 +190,19 @@ module Tapioca
190
190
 
191
191
  private
192
192
 
193
+ sig do
194
+ params(fixed: T.untyped, lower: T.untyped, upper: T.untyped)
195
+ .returns(T.proc.returns(T::Hash[Symbol, T.untyped]))
196
+ end
197
+ def build_bounds_proc(fixed, lower, upper)
198
+ bounds = {}
199
+ bounds[:fixed] = fixed unless fixed.nil?
200
+ bounds[:lower] = lower unless lower.nil?
201
+ bounds[:upper] = upper unless upper.nil?
202
+
203
+ -> { bounds }
204
+ end
205
+
193
206
  sig do
194
207
  type_parameters(:Result)
195
208
  .params(block: T.proc.returns(T.type_parameter(:Result)))
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.8.0"
5
+ VERSION = "0.8.1"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2022-05-13 00:00:00.000000000 Z
14
+ date: 2022-05-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler