tapioca 0.10.1 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -3
  3. data/lib/tapioca/cli.rb +24 -12
  4. data/lib/tapioca/commands/annotations.rb +2 -2
  5. data/lib/tapioca/commands/check_shims.rb +13 -21
  6. data/lib/tapioca/commands/command.rb +2 -2
  7. data/lib/tapioca/commands/command_without_tracker.rb +18 -0
  8. data/lib/tapioca/commands/configure.rb +3 -3
  9. data/lib/tapioca/commands/dsl.rb +16 -11
  10. data/lib/tapioca/commands/gem.rb +5 -5
  11. data/lib/tapioca/commands/require.rb +2 -2
  12. data/lib/tapioca/commands/todo.rb +2 -2
  13. data/lib/tapioca/commands.rb +1 -0
  14. data/lib/tapioca/dsl/compiler.rb +3 -3
  15. data/lib/tapioca/dsl/compilers/aasm.rb +4 -4
  16. data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +1 -1
  17. data/lib/tapioca/dsl/compilers/action_mailer.rb +1 -1
  18. data/lib/tapioca/dsl/compilers/active_job.rb +2 -2
  19. data/lib/tapioca/dsl/compilers/active_model_attributes.rb +1 -1
  20. data/lib/tapioca/dsl/compilers/active_record_associations.rb +48 -13
  21. data/lib/tapioca/dsl/compilers/active_record_columns.rb +22 -22
  22. data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +1 -1
  23. data/lib/tapioca/dsl/compilers/active_record_relations.rb +52 -48
  24. data/lib/tapioca/dsl/compilers/active_record_scope.rb +3 -3
  25. data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +2 -2
  26. data/lib/tapioca/dsl/compilers/active_storage.rb +2 -2
  27. data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +1 -1
  28. data/lib/tapioca/dsl/compilers/config.rb +2 -2
  29. data/lib/tapioca/dsl/compilers/graphql_input_object.rb +1 -0
  30. data/lib/tapioca/dsl/compilers/graphql_mutation.rb +1 -0
  31. data/lib/tapioca/dsl/compilers/identity_cache.rb +12 -12
  32. data/lib/tapioca/dsl/compilers/protobuf.rb +21 -10
  33. data/lib/tapioca/dsl/compilers/rails_generators.rb +2 -2
  34. data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +1 -1
  35. data/lib/tapioca/dsl/compilers/smart_properties.rb +2 -2
  36. data/lib/tapioca/dsl/compilers/state_machines.rb +24 -24
  37. data/lib/tapioca/dsl/compilers/url_helpers.rb +1 -1
  38. data/lib/tapioca/dsl/compilers.rb +1 -1
  39. data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +19 -0
  40. data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +1 -1
  41. data/lib/tapioca/dsl/pipeline.rb +5 -4
  42. data/lib/tapioca/executor.rb +2 -2
  43. data/lib/tapioca/gem/events.rb +1 -1
  44. data/lib/tapioca/gem/listeners/foreign_constants.rb +3 -2
  45. data/lib/tapioca/gem/listeners/methods.rb +3 -3
  46. data/lib/tapioca/gem/listeners/mixins.rb +3 -7
  47. data/lib/tapioca/gem/listeners/source_location.rb +1 -1
  48. data/lib/tapioca/gem/listeners/subconstants.rb +1 -1
  49. data/lib/tapioca/gem/listeners/yard_doc.rb +1 -1
  50. data/lib/tapioca/gem/pipeline.rb +11 -9
  51. data/lib/tapioca/gemfile.rb +4 -4
  52. data/lib/tapioca/helpers/config_helper.rb +4 -4
  53. data/lib/tapioca/helpers/env_helper.rb +1 -0
  54. data/lib/tapioca/helpers/gem_helper.rb +17 -5
  55. data/lib/tapioca/helpers/rbi_files_helper.rb +3 -3
  56. data/lib/tapioca/helpers/rbi_helper.rb +5 -13
  57. data/lib/tapioca/helpers/sorbet_helper.rb +3 -5
  58. data/lib/tapioca/helpers/source_uri.rb +1 -1
  59. data/lib/tapioca/helpers/test/dsl_compiler.rb +1 -1
  60. data/lib/tapioca/loaders/dsl.rb +9 -7
  61. data/lib/tapioca/loaders/gem.rb +2 -2
  62. data/lib/tapioca/loaders/loader.rb +6 -6
  63. data/lib/tapioca/rbi_ext/model.rb +8 -5
  64. data/lib/tapioca/rbi_formatter.rb +2 -2
  65. data/lib/tapioca/runtime/generic_type_registry.rb +22 -2
  66. data/lib/tapioca/runtime/reflection.rb +63 -2
  67. data/lib/tapioca/runtime/trackers/autoload.rb +3 -0
  68. data/lib/tapioca/runtime/trackers/constant_definition.rb +13 -5
  69. data/lib/tapioca/runtime/trackers/mixin.rb +37 -36
  70. data/lib/tapioca/runtime/trackers/required_ancestor.rb +17 -4
  71. data/lib/tapioca/runtime/trackers/tracker.rb +45 -0
  72. data/lib/tapioca/runtime/trackers.rb +27 -1
  73. data/lib/tapioca/sorbet_ext/generic_name_patch.rb +17 -6
  74. data/lib/tapioca/static/symbol_loader.rb +3 -3
  75. data/lib/tapioca/static/symbol_table_parser.rb +6 -0
  76. data/lib/tapioca/version.rb +1 -1
  77. data/lib/tapioca.rb +0 -10
  78. metadata +8 -20
@@ -152,7 +152,7 @@ module Tapioca
152
152
  mod.create_method(
153
153
  "#{association_name}_attributes=",
154
154
  parameters: [create_param("attributes", type: "T.untyped")],
155
- return_type: "T.untyped"
155
+ return_type: "T.untyped",
156
156
  )
157
157
  end
158
158
  end
@@ -180,7 +180,7 @@ module Tapioca
180
180
  params(
181
181
  klass: RBI::Scope,
182
182
  association_name: T.any(String, Symbol),
183
- reflection: ReflectionType
183
+ reflection: ReflectionType,
184
184
  ).void
185
185
  end
186
186
  def populate_single_assoc_getter_setter(klass, association_name, reflection)
@@ -194,7 +194,7 @@ module Tapioca
194
194
  klass.create_method(
195
195
  "#{association_name}=",
196
196
  parameters: [create_param("value", type: association_type)],
197
- return_type: "void"
197
+ return_type: "void",
198
198
  )
199
199
  klass.create_method(
200
200
  "reload_#{association_name}",
@@ -207,7 +207,7 @@ module Tapioca
207
207
  create_rest_param("args", type: "T.untyped"),
208
208
  create_block_param("blk", type: "T.untyped"),
209
209
  ],
210
- return_type: association_class
210
+ return_type: association_class,
211
211
  )
212
212
  klass.create_method(
213
213
  "create_#{association_name}",
@@ -215,7 +215,7 @@ module Tapioca
215
215
  create_rest_param("args", type: "T.untyped"),
216
216
  create_block_param("blk", type: "T.untyped"),
217
217
  ],
218
- return_type: association_class
218
+ return_type: association_class,
219
219
  )
220
220
  klass.create_method(
221
221
  "create_#{association_name}!",
@@ -223,7 +223,7 @@ module Tapioca
223
223
  create_rest_param("args", type: "T.untyped"),
224
224
  create_block_param("blk", type: "T.untyped"),
225
225
  ],
226
- return_type: association_class
226
+ return_type: association_class,
227
227
  )
228
228
  end
229
229
  end
@@ -232,7 +232,7 @@ module Tapioca
232
232
  params(
233
233
  klass: RBI::Scope,
234
234
  association_name: T.any(String, Symbol),
235
- reflection: ReflectionType
235
+ reflection: ReflectionType,
236
236
  ).void
237
237
  end
238
238
  def populate_collection_assoc_getter_setter(klass, association_name, reflection)
@@ -241,6 +241,7 @@ module Tapioca
241
241
 
242
242
  klass.create_method(
243
243
  association_name.to_s,
244
+ comments: association_comments(reflection),
244
245
  return_type: relation_class,
245
246
  )
246
247
  klass.create_method(
@@ -250,18 +251,18 @@ module Tapioca
250
251
  )
251
252
  klass.create_method(
252
253
  "#{association_name.to_s.singularize}_ids",
253
- return_type: "T::Array[T.untyped]"
254
+ return_type: "T::Array[T.untyped]",
254
255
  )
255
256
  klass.create_method(
256
257
  "#{association_name.to_s.singularize}_ids=",
257
258
  parameters: [create_param("ids", type: "T::Array[T.untyped]")],
258
- return_type: "T::Array[T.untyped]"
259
+ return_type: "T::Array[T.untyped]",
259
260
  )
260
261
  end
261
262
 
262
263
  sig do
263
264
  params(
264
- reflection: ReflectionType
265
+ reflection: ReflectionType,
265
266
  ).returns(String)
266
267
  end
267
268
  def type_for(reflection)
@@ -274,7 +275,7 @@ module Tapioca
274
275
 
275
276
  sig do
276
277
  params(
277
- reflection: ReflectionType
278
+ reflection: ReflectionType,
278
279
  ).void
279
280
  end
280
281
  def validate_reflection!(reflection)
@@ -320,9 +321,43 @@ module Tapioca
320
321
  end
321
322
  end
322
323
 
324
+ sig { params(reflection: ReflectionType).returns(T::Array[RBI::Comment]) }
325
+ def association_comments(reflection)
326
+ anchor_name = case reflection
327
+ when ActiveRecord::Reflection::HasOneReflection
328
+ "the-has-one-association"
329
+ when ActiveRecord::Reflection::HasManyReflection
330
+ "the-has-many-association"
331
+ when ActiveRecord::Reflection::HasAndBelongsToManyReflection
332
+ "the-has-and-belongs-to-many-association"
333
+ when ActiveRecord::Reflection::BelongsToReflection
334
+ "the-belongs-to-association"
335
+ when ActiveRecord::Reflection::ThroughReflection
336
+ delegate_reflection = reflection.send(:delegate_reflection)
337
+ declaration = declaration(delegate_reflection)
338
+ if T.must(declaration).match?("has_one")
339
+ "the-has-one-through-association"
340
+ else
341
+ "the-has-many-through-association"
342
+ end
343
+ end
344
+
345
+ if anchor_name
346
+ url = "https://guides.rubyonrails.org/association_basics.html##{anchor_name}"
347
+ association_name = anchor_name.sub(/^the-(.*)-association$/, '\1')
348
+ comment = <<~MSG
349
+ This method is created by ActiveRecord on the `#{reflection.active_record.name}` class because it declared `#{declaration(reflection)}`.
350
+ 🔗 [Rails guide for `#{association_name.gsub("-", "_")}` association](#{url})
351
+ MSG
352
+ [RBI::Comment.new(comment)]
353
+ else
354
+ []
355
+ end
356
+ end
357
+
323
358
  sig do
324
359
  params(
325
- reflection: ReflectionType
360
+ reflection: ReflectionType,
326
361
  ).returns(String)
327
362
  end
328
363
  def relation_type_for(reflection)
@@ -346,7 +381,7 @@ module Tapioca
346
381
 
347
382
  sig do
348
383
  params(
349
- reflection: ReflectionType
384
+ reflection: ReflectionType,
350
385
  ).returns(T::Boolean)
351
386
  end
352
387
  def polymorphic_association?(reflection)
@@ -152,14 +152,14 @@ module Tapioca
152
152
  name: String,
153
153
  methods_to_add: T.nilable(T::Array[String]),
154
154
  return_type: String,
155
- parameters: T::Array[[String, String]]
155
+ parameters: T::Array[[String, String]],
156
156
  ).void
157
157
  end
158
158
  def add_method(klass, name, methods_to_add, return_type: "void", parameters: [])
159
159
  klass.create_method(
160
160
  name,
161
161
  parameters: parameters.map { |param, type| create_param(param, type: type) },
162
- return_type: return_type
162
+ return_type: return_type,
163
163
  ) if methods_to_add.nil? || methods_to_add.include?(name)
164
164
  end
165
165
 
@@ -168,7 +168,7 @@ module Tapioca
168
168
  klass: RBI::Scope,
169
169
  column_name: String,
170
170
  attribute_name: String,
171
- methods_to_add: T.nilable(T::Array[String])
171
+ methods_to_add: T.nilable(T::Array[String]),
172
172
  ).void
173
173
  end
174
174
  def add_methods_for_attribute(klass, column_name, attribute_name = column_name, methods_to_add = nil)
@@ -180,7 +180,7 @@ module Tapioca
180
180
  klass,
181
181
  attribute_name.to_s,
182
182
  methods_to_add,
183
- return_type: getter_type
183
+ return_type: getter_type,
184
184
  )
185
185
 
186
186
  # Added by ActiveRecord::AttributeMethods::Write
@@ -190,7 +190,7 @@ module Tapioca
190
190
  "#{attribute_name}=",
191
191
  methods_to_add,
192
192
  parameters: [["value", setter_type]],
193
- return_type: setter_type
193
+ return_type: setter_type,
194
194
  )
195
195
 
196
196
  # Added by ActiveRecord::AttributeMethods::Query
@@ -199,7 +199,7 @@ module Tapioca
199
199
  klass,
200
200
  "#{attribute_name}?",
201
201
  methods_to_add,
202
- return_type: "T::Boolean"
202
+ return_type: "T::Boolean",
203
203
  )
204
204
 
205
205
  # Added by ActiveRecord::AttributeMethods::Dirty
@@ -208,37 +208,37 @@ module Tapioca
208
208
  klass,
209
209
  "#{attribute_name}_before_last_save",
210
210
  methods_to_add,
211
- return_type: as_nilable_type(getter_type)
211
+ return_type: as_nilable_type(getter_type),
212
212
  )
213
213
  add_method(
214
214
  klass,
215
215
  "#{attribute_name}_change_to_be_saved",
216
216
  methods_to_add,
217
- return_type: "T.nilable([#{getter_type}, #{getter_type}])"
217
+ return_type: "T.nilable([#{getter_type}, #{getter_type}])",
218
218
  )
219
219
  add_method(
220
220
  klass,
221
221
  "#{attribute_name}_in_database",
222
222
  methods_to_add,
223
- return_type: as_nilable_type(getter_type)
223
+ return_type: as_nilable_type(getter_type),
224
224
  )
225
225
  add_method(
226
226
  klass,
227
227
  "saved_change_to_#{attribute_name}",
228
228
  methods_to_add,
229
- return_type: "T.nilable([#{getter_type}, #{getter_type}])"
229
+ return_type: "T.nilable([#{getter_type}, #{getter_type}])",
230
230
  )
231
231
  add_method(
232
232
  klass,
233
233
  "saved_change_to_#{attribute_name}?",
234
234
  methods_to_add,
235
- return_type: "T::Boolean"
235
+ return_type: "T::Boolean",
236
236
  )
237
237
  add_method(
238
238
  klass,
239
239
  "will_save_change_to_#{attribute_name}?",
240
240
  methods_to_add,
241
- return_type: "T::Boolean"
241
+ return_type: "T::Boolean",
242
242
  )
243
243
 
244
244
  # Added by ActiveModel::Dirty
@@ -247,47 +247,47 @@ module Tapioca
247
247
  klass,
248
248
  "#{attribute_name}_change",
249
249
  methods_to_add,
250
- return_type: "T.nilable([#{getter_type}, #{getter_type}])"
250
+ return_type: "T.nilable([#{getter_type}, #{getter_type}])",
251
251
  )
252
252
  add_method(
253
253
  klass,
254
254
  "#{attribute_name}_changed?",
255
255
  methods_to_add,
256
- return_type: "T::Boolean"
256
+ return_type: "T::Boolean",
257
257
  )
258
258
  add_method(
259
259
  klass,
260
260
  "#{attribute_name}_will_change!",
261
- methods_to_add
261
+ methods_to_add,
262
262
  )
263
263
  add_method(
264
264
  klass,
265
265
  "#{attribute_name}_was",
266
266
  methods_to_add,
267
- return_type: as_nilable_type(getter_type)
267
+ return_type: as_nilable_type(getter_type),
268
268
  )
269
269
  add_method(
270
270
  klass,
271
271
  "#{attribute_name}_previous_change",
272
272
  methods_to_add,
273
- return_type: "T.nilable([#{getter_type}, #{getter_type}])"
273
+ return_type: "T.nilable([#{getter_type}, #{getter_type}])",
274
274
  )
275
275
  add_method(
276
276
  klass,
277
277
  "#{attribute_name}_previously_changed?",
278
278
  methods_to_add,
279
- return_type: "T::Boolean"
279
+ return_type: "T::Boolean",
280
280
  )
281
281
  add_method(
282
282
  klass,
283
283
  "#{attribute_name}_previously_was",
284
284
  methods_to_add,
285
- return_type: as_nilable_type(getter_type)
285
+ return_type: as_nilable_type(getter_type),
286
286
  )
287
287
  add_method(
288
288
  klass,
289
289
  "restore_#{attribute_name}!",
290
- methods_to_add
290
+ methods_to_add,
291
291
  )
292
292
 
293
293
  # Added by ActiveRecord::AttributeMethods::BeforeTypeCast
@@ -296,13 +296,13 @@ module Tapioca
296
296
  klass,
297
297
  "#{attribute_name}_before_type_cast",
298
298
  methods_to_add,
299
- return_type: "T.untyped"
299
+ return_type: "T.untyped",
300
300
  )
301
301
  add_method(
302
302
  klass,
303
303
  "#{attribute_name}_came_from_user?",
304
304
  methods_to_add,
305
- return_type: "T::Boolean"
305
+ return_type: "T::Boolean",
306
306
  )
307
307
  end
308
308
  end
@@ -100,7 +100,7 @@ module Tapioca
100
100
  mod.create_method(
101
101
  name,
102
102
  parameters: [create_rest_param("fixture_names", type: "T.any(String, Symbol)")],
103
- return_type: "T.untyped"
103
+ return_type: "T.untyped",
104
104
  )
105
105
  end
106
106
  end
@@ -62,6 +62,16 @@ module Tapioca
62
62
  # `Model::PrivateRelation` modules, so that, for example, `find_by` and `all` can be chained off of the
63
63
  # `Model` class.
64
64
  #
65
+ # **A note on find**: `find` is typed as `T.untyped` by default.
66
+ #
67
+ # While it is often used in the manner of `Model.find(id)`, Rails does support pasing in an array to find, which
68
+ # would then return a `T::Enumerable[Model]`. This would force a static cast everywhere find is used to avoid type
69
+ # errors. This is not ideal considering very few users of find use the array syntax over a where. With untyped,
70
+ # this cast is optional and so it was decided to avoid typing it. If you need runtime guarentees when using `find`
71
+ # the best method of doing so is by casting the return value to the model: `T.cast(Model.find(id), Model)`.
72
+ # `find_by` does guarentee a return value of `Model`, so find can can be refactored accordingly:
73
+ # `Model.find_by!(id: id)`. This will avoid the cast requirement at runtime.
74
+ #
65
75
  # **CAUTION**: The generated relation classes are named `PrivateXXX` intentionally to reflect the fact
66
76
  # that they represent private subconstants of the Active Record model. As such, these types do not
67
77
  # exist at runtime, and their counterparts that do exist at runtime are marked `private_constant` anyway.
@@ -178,12 +188,12 @@ module Tapioca
178
188
  ASSOCIATION_METHODS = T.let(
179
189
  ::ActiveRecord::AssociationRelation.instance_methods -
180
190
  ::ActiveRecord::Relation.instance_methods,
181
- T::Array[Symbol]
191
+ T::Array[Symbol],
182
192
  )
183
193
  COLLECTION_PROXY_METHODS = T.let(
184
194
  ::ActiveRecord::Associations::CollectionProxy.instance_methods -
185
195
  ::ActiveRecord::AssociationRelation.instance_methods,
186
- T::Array[Symbol]
196
+ T::Array[Symbol],
187
197
  )
188
198
 
189
199
  QUERY_METHODS = T.let(begin
@@ -204,14 +214,14 @@ module Tapioca
204
214
  end, T::Array[Symbol])
205
215
  WHERE_CHAIN_QUERY_METHODS = T.let(
206
216
  ActiveRecord::QueryMethods::WhereChain.instance_methods(false),
207
- T::Array[Symbol]
217
+ T::Array[Symbol],
208
218
  )
209
219
  FINDER_METHODS = T.let(ActiveRecord::FinderMethods.instance_methods(false), T::Array[Symbol])
210
220
  CALCULATION_METHODS = T.let(ActiveRecord::Calculations.instance_methods(false), T::Array[Symbol])
211
221
  ENUMERABLE_QUERY_METHODS = T.let([:any?, :many?, :none?, :one?], T::Array[Symbol])
212
222
  FIND_OR_CREATE_METHODS = T.let(
213
223
  [:find_or_create_by, :find_or_create_by!, :find_or_initialize_by, :create_or_find_by, :create_or_find_by!],
214
- T::Array[Symbol]
224
+ T::Array[Symbol],
215
225
  )
216
226
  BUILDER_METHODS = T.let([:new, :build, :create, :create!], T::Array[Symbol])
217
227
 
@@ -233,15 +243,9 @@ module Tapioca
233
243
  # The model always extends the generated relation module
234
244
  model.create_extend(RelationMethodsModuleName)
235
245
 
236
- # This feature is only available in versions of Sorbet with special support for
237
- # handling `NilClass` returns from `to_ary`. We should not be typing `to_ary` like
238
- # this for older versions since it will make all flatten operations be
239
- # `T::Array[NilClass]`, otherwise.
240
- if sorbet_supports?(:to_ary_nil_support)
241
- # Type the `to_ary` method as returning `NilClass` so that flatten stops recursing
242
- # See https://github.com/sorbet/sorbet/pull/4706 for details
243
- model.create_method("to_ary", return_type: "NilClass", visibility: RBI::Private.new)
244
- end
246
+ # Type the `to_ary` method as returning `NilClass` so that flatten stops recursing
247
+ # See https://github.com/sorbet/sorbet/pull/4706 for details
248
+ model.create_method("to_ary", return_type: "NilClass", visibility: RBI::Private.new)
245
249
 
246
250
  create_relation_class(model)
247
251
  create_association_relation_class(model)
@@ -292,7 +296,7 @@ module Tapioca
292
296
  def create_association_relation_where_chain_class(model)
293
297
  model.create_class(
294
298
  AssociationRelationWhereChainClassName,
295
- superclass_name: AssociationRelationClassName
299
+ superclass_name: AssociationRelationClassName,
296
300
  ) do |klass|
297
301
  create_where_chain_methods(klass, AssociationRelationClassName)
298
302
  klass.create_type_variable("Elem", type: "type_member", fixed: constant_name)
@@ -310,7 +314,7 @@ module Tapioca
310
314
  create_param("opts", type: "T.untyped"),
311
315
  create_rest_param("rest", type: "T.untyped"),
312
316
  ],
313
- return_type: return_type
317
+ return_type: return_type,
314
318
  )
315
319
  when :associated, :missing
316
320
  klass.create_method(
@@ -318,7 +322,7 @@ module Tapioca
318
322
  parameters: [
319
323
  create_rest_param("args", type: "T.untyped"),
320
324
  ],
321
- return_type: return_type
325
+ return_type: return_type,
322
326
  )
323
327
  end
324
328
  end
@@ -374,12 +378,12 @@ module Tapioca
374
378
  parameters: [
375
379
  create_rest_param("records", type: model_collection),
376
380
  ],
377
- return_type: AssociationsCollectionProxyClassName
381
+ return_type: AssociationsCollectionProxyClassName,
378
382
  )
379
383
  when :clear
380
384
  klass.create_method(
381
385
  method_name.to_s,
382
- return_type: AssociationsCollectionProxyClassName
386
+ return_type: AssociationsCollectionProxyClassName,
383
387
  )
384
388
  when :delete, :destroy
385
389
  klass.create_method(
@@ -387,12 +391,12 @@ module Tapioca
387
391
  parameters: [
388
392
  create_rest_param("records", type: model_or_id_collection),
389
393
  ],
390
- return_type: "T::Array[#{constant_name}]"
394
+ return_type: "T::Array[#{constant_name}]",
391
395
  )
392
396
  when :load_target
393
397
  klass.create_method(
394
398
  method_name.to_s,
395
- return_type: "T::Array[#{constant_name}]"
399
+ return_type: "T::Array[#{constant_name}]",
396
400
  )
397
401
  when :replace
398
402
  klass.create_method(
@@ -400,19 +404,19 @@ module Tapioca
400
404
  parameters: [
401
405
  create_param("other_array", type: model_collection),
402
406
  ],
403
- return_type: "T::Array[#{constant_name}]"
407
+ return_type: "T::Array[#{constant_name}]",
404
408
  )
405
409
  when :reset_scope
406
410
  # skip
407
411
  when :scope
408
412
  klass.create_method(
409
413
  method_name.to_s,
410
- return_type: AssociationRelationClassName
414
+ return_type: AssociationRelationClassName,
411
415
  )
412
416
  when :target
413
417
  klass.create_method(
414
418
  method_name.to_s,
415
- return_type: "T::Array[#{constant_name}]"
419
+ return_type: "T::Array[#{constant_name}]",
416
420
  )
417
421
  end
418
422
  end
@@ -441,7 +445,7 @@ module Tapioca
441
445
  parameters: [
442
446
  create_rest_param("args", type: "T.untyped"),
443
447
  create_block_param("blk", type: "T.untyped"),
444
- ]
448
+ ],
445
449
  )
446
450
  end
447
451
  end
@@ -467,7 +471,7 @@ module Tapioca
467
471
  association_relation_methods_module.create_method(
468
472
  method_name.to_s,
469
473
  parameters: parameters,
470
- return_type: "ActiveRecord::Result"
474
+ return_type: "ActiveRecord::Result",
471
475
  )
472
476
  when :insert, :insert!, :upsert
473
477
  parameters = [
@@ -483,7 +487,7 @@ module Tapioca
483
487
  association_relation_methods_module.create_method(
484
488
  method_name.to_s,
485
489
  parameters: parameters,
486
- return_type: "ActiveRecord::Result"
490
+ return_type: "ActiveRecord::Result",
487
491
  )
488
492
  when :proxy_association
489
493
  # skip - private method
@@ -496,7 +500,7 @@ module Tapioca
496
500
  create_common_method(
497
501
  "destroy_all",
498
502
  common_relation_methods_module,
499
- return_type: "T::Array[#{constant_name}]"
503
+ return_type: "T::Array[#{constant_name}]",
500
504
  )
501
505
 
502
506
  FINDER_METHODS.each do |method_name|
@@ -508,7 +512,7 @@ module Tapioca
508
512
  parameters: [
509
513
  create_opt_param("conditions", type: "T.untyped", default: ":none"),
510
514
  ],
511
- return_type: "T::Boolean"
515
+ return_type: "T::Boolean",
512
516
  )
513
517
  when :include?, :member?
514
518
  create_common_method(
@@ -517,7 +521,7 @@ module Tapioca
517
521
  parameters: [
518
522
  create_param("record", type: "T.untyped"),
519
523
  ],
520
- return_type: "T::Boolean"
524
+ return_type: "T::Boolean",
521
525
  )
522
526
  when :find
523
527
  create_common_method(
@@ -526,7 +530,7 @@ module Tapioca
526
530
  parameters: [
527
531
  create_rest_param("args", type: "T.untyped"),
528
532
  ],
529
- return_type: "T.untyped"
533
+ return_type: "T.untyped",
530
534
  )
531
535
  when :find_by
532
536
  create_common_method(
@@ -535,7 +539,7 @@ module Tapioca
535
539
  parameters: [
536
540
  create_rest_param("args", type: "T.untyped"),
537
541
  ],
538
- return_type: as_nilable_type(constant_name)
542
+ return_type: as_nilable_type(constant_name),
539
543
  )
540
544
  when :find_by!
541
545
  create_common_method(
@@ -544,7 +548,7 @@ module Tapioca
544
548
  parameters: [
545
549
  create_rest_param("args", type: "T.untyped"),
546
550
  ],
547
- return_type: constant_name
551
+ return_type: constant_name,
548
552
  )
549
553
  when :find_sole_by
550
554
  create_common_method(
@@ -554,14 +558,14 @@ module Tapioca
554
558
  create_param("arg", type: "T.untyped"),
555
559
  create_rest_param("args", type: "T.untyped"),
556
560
  ],
557
- return_type: constant_name
561
+ return_type: constant_name,
558
562
  )
559
563
  when :sole
560
564
  create_common_method(
561
565
  "sole",
562
566
  common_relation_methods_module,
563
567
  parameters: [],
564
- return_type: constant_name
568
+ return_type: constant_name,
565
569
  )
566
570
  when :first, :last, :take
567
571
  create_common_method(
@@ -570,7 +574,7 @@ module Tapioca
570
574
  parameters: [
571
575
  create_opt_param("limit", type: "T.untyped", default: "nil"),
572
576
  ],
573
- return_type: "T.untyped"
577
+ return_type: "T.untyped",
574
578
  )
575
579
  when :raise_record_not_found_exception!
576
580
  # skip
@@ -584,7 +588,7 @@ module Tapioca
584
588
  create_common_method(
585
589
  method_name,
586
590
  common_relation_methods_module,
587
- return_type: return_type
591
+ return_type: return_type,
588
592
  )
589
593
  end
590
594
  end
@@ -598,7 +602,7 @@ module Tapioca
598
602
  parameters: [
599
603
  create_param("column_name", type: "T.any(String, Symbol)"),
600
604
  ],
601
- return_type: "T.untyped"
605
+ return_type: "T.untyped",
602
606
  )
603
607
  when :calculate
604
608
  create_common_method(
@@ -608,7 +612,7 @@ module Tapioca
608
612
  create_param("operation", type: "Symbol"),
609
613
  create_param("column_name", type: "T.any(String, Symbol)"),
610
614
  ],
611
- return_type: "T.untyped"
615
+ return_type: "T.untyped",
612
616
  )
613
617
  when :count
614
618
  create_common_method(
@@ -617,7 +621,7 @@ module Tapioca
617
621
  parameters: [
618
622
  create_opt_param("column_name", type: "T.untyped", default: "nil"),
619
623
  ],
620
- return_type: "T.untyped"
624
+ return_type: "T.untyped",
621
625
  )
622
626
  when :ids
623
627
  create_common_method("ids", common_relation_methods_module, return_type: "Array")
@@ -628,7 +632,7 @@ module Tapioca
628
632
  parameters: [
629
633
  create_rest_param("column_names", type: "T.untyped"),
630
634
  ],
631
- return_type: "T.untyped"
635
+ return_type: "T.untyped",
632
636
  )
633
637
  when :sum
634
638
  create_common_method(
@@ -638,7 +642,7 @@ module Tapioca
638
642
  create_opt_param("column_name", type: "T.nilable(T.any(String, Symbol))", default: "nil"),
639
643
  create_block_param("block", type: "T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))"),
640
644
  ],
641
- return_type: "T.untyped"
645
+ return_type: "T.untyped",
642
646
  )
643
647
  end
644
648
  end
@@ -651,7 +655,7 @@ module Tapioca
651
655
  parameters: [
652
656
  create_block_param("block", type: block_type),
653
657
  ],
654
- return_type: "T::Boolean"
658
+ return_type: "T::Boolean",
655
659
  )
656
660
  end
657
661
 
@@ -664,7 +668,7 @@ module Tapioca
664
668
  create_param("attributes", type: "T.untyped"),
665
669
  create_block_param("block", type: block_type),
666
670
  ],
667
- return_type: constant_name
671
+ return_type: constant_name,
668
672
  )
669
673
  end
670
674
 
@@ -676,7 +680,7 @@ module Tapioca
676
680
  create_opt_param("attributes", type: "T.untyped", default: "nil"),
677
681
  create_block_param("block", type: "T.nilable(T.proc.params(object: #{constant_name}).void)"),
678
682
  ],
679
- return_type: constant_name
683
+ return_type: constant_name,
680
684
  )
681
685
  end
682
686
  end
@@ -686,14 +690,14 @@ module Tapioca
686
690
  name: T.any(Symbol, String),
687
691
  common_relation_methods_module: RBI::Scope,
688
692
  parameters: T::Array[RBI::TypedParam],
689
- return_type: T.nilable(String)
693
+ return_type: T.nilable(String),
690
694
  ).void
691
695
  end
692
696
  def create_common_method(name, common_relation_methods_module, parameters: [], return_type: nil)
693
697
  common_relation_methods_module.create_method(
694
698
  name.to_s,
695
699
  parameters: parameters,
696
- return_type: return_type || "void"
700
+ return_type: return_type || "void",
697
701
  )
698
702
  end
699
703
 
@@ -718,12 +722,12 @@ module Tapioca
718
722
  relation_methods_module.create_method(
719
723
  name.to_s,
720
724
  parameters: parameters,
721
- return_type: relation_return_type
725
+ return_type: relation_return_type,
722
726
  )
723
727
  association_relation_methods_module.create_method(
724
728
  name.to_s,
725
729
  parameters: parameters,
726
- return_type: association_return_type
730
+ return_type: association_return_type,
727
731
  )
728
732
  end
729
733
  end