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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df803cbfcb6a400e88175b21c0bfd3d5c8089853d5ca09cf8f7b7d0076ce201f
4
- data.tar.gz: fc580b1ae8202f4d94a45d75665c07a072c7ffde6652aaa3580dd1e8a196288c
3
+ metadata.gz: cc4a2a8ab8f9e4f81b9e600e00c689bc79578aa6267a9f99d44eefab1b6b6316
4
+ data.tar.gz: 16c553d22afbf5bbc0fb8d366fb95e41be55f436253d7161dece29577ea7e586
5
5
  SHA512:
6
- metadata.gz: a36a8f3dc321ce2cf8f5402f3b00aee7ef9e6ea2748ee95371b64dceec217df218fd8dc6ca786cfce90478c9c0db7c14bde1f43276f76a65b4ed2d6fa7093672
7
- data.tar.gz: f688b633d7e0ed4627a5929aef8293619641609c143c43082b291330f9fe5fb2c5a72e9e70be0f2d57274908b4f1fc48dd6ff8dcb4d7d815c894af9567a21417
6
+ metadata.gz: 35ae53d442a9b2342d44f0bfe4889ed8cd59dbae526468947674a4ed1c9ceaecd84b2cedb61e997ca9b2f5481e335e61678a3be04f6f93e8f8ab14396db99030
7
+ data.tar.gz: e95259f37e07b7a9de62ebdd9c620ab75f6e4e07695a757608172016948f8fc6b22b5847759f12f69eeceb56f80dacd84bc3b4dc6c1e11a09c32764d33970a4d
@@ -109,7 +109,7 @@ module Tapioca
109
109
  return "T.untyped"
110
110
  end
111
111
 
112
- "T.nilable(#{type})"
112
+ as_nilable_type(type)
113
113
  end
114
114
 
115
115
  sig { params(klass: RBI::Scope, method: String, type: String).void }
@@ -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 = "T.nilable(#{association_class})"
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: "T.nilable(#{constant_name})"
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
- "T.nilable(#{constant_name})"
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 = "T.nilable(#{type})" if field.null && type != "T.untyped"
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
- "T.nilable(::#{cache_type})"
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: "::#{constant}"
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: "T.nilable(::#{constant})"
191
+ return_type: as_nilable_type(type)
190
192
  )
191
193
  else
192
194
  klass.create_method(
@@ -111,7 +111,7 @@ module Tapioca
111
111
  if arg.required || arg.default
112
112
  type
113
113
  else
114
- "T.nilable(#{type})"
114
+ as_nilable_type(type)
115
115
  end
116
116
  end
117
117
  end
@@ -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 = "T.nilable(#{type})" if might_be_optional
147
+ type = as_nilable_type(type) if might_be_optional
151
148
 
152
149
  type
153
150
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.6.2"
5
+ VERSION = "0.6.3"
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.6.2
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-20 00:00:00.000000000 Z
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: 0.19.2
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: 0.19.2
125
+ version: 1.2.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: yard-sorbet
128
128
  requirement: !ruby/object:Gem::Requirement