tapioca 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tapioca/compilers/dsl/active_model_attributes.rb +1 -1
- data/lib/tapioca/compilers/dsl/active_record_associations.rb +1 -1
- data/lib/tapioca/compilers/dsl/active_record_columns.rb +0 -6
- data/lib/tapioca/compilers/dsl/active_record_relations.rb +11 -2
- data/lib/tapioca/compilers/dsl/active_record_typed_store.rb +1 -1
- data/lib/tapioca/compilers/dsl/base.rb +9 -0
- data/lib/tapioca/compilers/dsl/identity_cache.rb +5 -3
- data/lib/tapioca/compilers/dsl/rails_generators.rb +1 -1
- data/lib/tapioca/compilers/dsl/smart_properties.rb +1 -4
- data/lib/tapioca/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc4a2a8ab8f9e4f81b9e600e00c689bc79578aa6267a9f99d44eefab1b6b6316
|
4
|
+
data.tar.gz: 16c553d22afbf5bbc0fb8d366fb95e41be55f436253d7161dece29577ea7e586
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35ae53d442a9b2342d44f0bfe4889ed8cd59dbae526468947674a4ed1c9ceaecd84b2cedb61e997ca9b2f5481e335e61678a3be04f6f93e8f8ab14396db99030
|
7
|
+
data.tar.gz: e95259f37e07b7a9de62ebdd9c620ab75f6e4e07695a757608172016948f8fc6b22b5847759f12f69eeceb56f80dacd84bc3b4dc6c1e11a09c32764d33970a4d
|
@@ -184,7 +184,7 @@ module Tapioca
|
|
184
184
|
end
|
185
185
|
def populate_single_assoc_getter_setter(klass, constant, association_name, reflection)
|
186
186
|
association_class = type_for(constant, reflection)
|
187
|
-
association_type =
|
187
|
+
association_type = as_nilable_type(association_class)
|
188
188
|
|
189
189
|
klass.create_method(
|
190
190
|
association_name.to_s,
|
@@ -293,12 +293,6 @@ module Tapioca
|
|
293
293
|
return_type: "T::Boolean"
|
294
294
|
)
|
295
295
|
end
|
296
|
-
|
297
|
-
sig { params(type: String).returns(String) }
|
298
|
-
def as_nilable_type(type)
|
299
|
-
return type if type.start_with?("T.nilable(") || type == "T.untyped"
|
300
|
-
"T.nilable(#{type})"
|
301
|
-
end
|
302
296
|
end
|
303
297
|
end
|
304
298
|
end
|
@@ -250,6 +250,15 @@ module Tapioca
|
|
250
250
|
sig { returns(String) }
|
251
251
|
attr_reader :constant_name
|
252
252
|
|
253
|
+
sig { params(type: String).returns(String) }
|
254
|
+
def as_nilable_type(type)
|
255
|
+
if type.start_with?("T.nilable(", "::T.nilable(") || type == "T.untyped" || type == "::T.untyped"
|
256
|
+
type
|
257
|
+
else
|
258
|
+
"T.nilable(#{type})"
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
253
262
|
sig { void }
|
254
263
|
def create_classes_and_includes
|
255
264
|
model.create_extend(CommonRelationMethodsModuleName)
|
@@ -546,7 +555,7 @@ module Tapioca
|
|
546
555
|
parameters: [
|
547
556
|
create_rest_param("args", type: "T.untyped"),
|
548
557
|
],
|
549
|
-
return_type:
|
558
|
+
return_type: as_nilable_type(constant_name)
|
550
559
|
)
|
551
560
|
when :find_by!
|
552
561
|
create_common_method(
|
@@ -570,7 +579,7 @@ module Tapioca
|
|
570
579
|
return_type = if method_name.end_with?("!")
|
571
580
|
constant_name
|
572
581
|
else
|
573
|
-
|
582
|
+
as_nilable_type(constant_name)
|
574
583
|
end
|
575
584
|
|
576
585
|
create_common_method(
|
@@ -107,7 +107,7 @@ module Tapioca
|
|
107
107
|
store_data.accessors.each do |accessor|
|
108
108
|
field = store_data.fields[accessor]
|
109
109
|
type = type_for(field.type_sym)
|
110
|
-
type =
|
110
|
+
type = as_nilable_type(type) if field.null
|
111
111
|
|
112
112
|
store_accessors_module = model.create_module("StoreAccessors")
|
113
113
|
generate_methods(store_accessors_module, field.name.to_s, type)
|
@@ -176,6 +176,15 @@ module Tapioca
|
|
176
176
|
return_type
|
177
177
|
end
|
178
178
|
|
179
|
+
sig { params(type: String).returns(String) }
|
180
|
+
def as_nilable_type(type)
|
181
|
+
if type.start_with?("T.nilable(", "::T.nilable(") || type == "T.untyped" || type == "::T.untyped"
|
182
|
+
type
|
183
|
+
else
|
184
|
+
"T.nilable(#{type})"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
179
188
|
sig { params(name: String).returns(T::Boolean) }
|
180
189
|
def valid_parameter_name?(name)
|
181
190
|
name.match?(/^[[[:alnum:]]_]+$/)
|
@@ -116,7 +116,7 @@ module Tapioca
|
|
116
116
|
if returns_collection
|
117
117
|
COLLECTION_TYPE.call(cache_type)
|
118
118
|
else
|
119
|
-
|
119
|
+
as_nilable_type(T.must(qualified_name_of(cache_type)))
|
120
120
|
end
|
121
121
|
rescue ArgumentError
|
122
122
|
"T.untyped"
|
@@ -175,18 +175,20 @@ module Tapioca
|
|
175
175
|
parameters << create_kw_opt_param("includes", default: "nil", type: "T.untyped")
|
176
176
|
|
177
177
|
if field.unique
|
178
|
+
type = T.must(qualified_name_of(constant))
|
179
|
+
|
178
180
|
klass.create_method(
|
179
181
|
"#{name}!",
|
180
182
|
class_method: true,
|
181
183
|
parameters: parameters,
|
182
|
-
return_type:
|
184
|
+
return_type: type
|
183
185
|
)
|
184
186
|
|
185
187
|
klass.create_method(
|
186
188
|
name,
|
187
189
|
class_method: true,
|
188
190
|
parameters: parameters,
|
189
|
-
return_type:
|
191
|
+
return_type: as_nilable_type(type)
|
190
192
|
)
|
191
193
|
else
|
192
194
|
klass.create_method(
|
@@ -143,11 +143,8 @@ module Tapioca
|
|
143
143
|
"T.untyped"
|
144
144
|
end
|
145
145
|
|
146
|
-
# Early return for "T.untyped", nothing more to do.
|
147
|
-
return type if type == "T.untyped"
|
148
|
-
|
149
146
|
might_be_optional = Proc === required || !required
|
150
|
-
type =
|
147
|
+
type = as_nilable_type(type) if might_be_optional
|
151
148
|
|
152
149
|
type
|
153
150
|
end
|
data/lib/tapioca/version.rb
CHANGED
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.6.
|
4
|
+
version: 0.6.3
|
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-01-
|
14
|
+
date: 2022-01-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -115,14 +115,14 @@ dependencies:
|
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
118
|
+
version: 1.2.0
|
119
119
|
type: :runtime
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: 1.2.0
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: yard-sorbet
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|