tapioca 0.16.10 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby_lsp/tapioca/addon.rb +24 -20
  3. data/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb +20 -20
  4. data/lib/tapioca/bundler_ext/auto_require_hook.rb +5 -10
  5. data/lib/tapioca/commands/abstract_dsl.rb +36 -62
  6. data/lib/tapioca/commands/abstract_gem.rb +23 -43
  7. data/lib/tapioca/commands/annotations.rb +27 -33
  8. data/lib/tapioca/commands/check_shims.rb +4 -13
  9. data/lib/tapioca/commands/command.rb +8 -20
  10. data/lib/tapioca/commands/command_without_tracker.rb +1 -1
  11. data/lib/tapioca/commands/configure.rb +11 -16
  12. data/lib/tapioca/commands/dsl_compiler_list.rb +2 -1
  13. data/lib/tapioca/commands/dsl_generate.rb +2 -1
  14. data/lib/tapioca/commands/dsl_verify.rb +2 -1
  15. data/lib/tapioca/commands/gem_generate.rb +4 -8
  16. data/lib/tapioca/commands/gem_sync.rb +2 -1
  17. data/lib/tapioca/commands/gem_verify.rb +3 -2
  18. data/lib/tapioca/commands/require.rb +3 -7
  19. data/lib/tapioca/commands/todo.rb +6 -10
  20. data/lib/tapioca/dsl/compiler.rb +28 -53
  21. data/lib/tapioca/dsl/compilers/aasm.rb +31 -41
  22. data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +7 -5
  23. data/lib/tapioca/dsl/compilers/action_mailer.rb +5 -3
  24. data/lib/tapioca/dsl/compilers/action_text.rb +5 -3
  25. data/lib/tapioca/dsl/compilers/active_job.rb +5 -8
  26. data/lib/tapioca/dsl/compilers/active_model_attributes.rb +9 -7
  27. data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +4 -2
  28. data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +4 -2
  29. data/lib/tapioca/dsl/compilers/active_record_associations.rb +16 -42
  30. data/lib/tapioca/dsl/compilers/active_record_columns.rb +19 -24
  31. data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +7 -5
  32. data/lib/tapioca/dsl/compilers/active_record_enum.rb +6 -4
  33. data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +53 -61
  34. data/lib/tapioca/dsl/compilers/active_record_relations.rb +86 -119
  35. data/lib/tapioca/dsl/compilers/active_record_scope.rb +7 -11
  36. data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +4 -2
  37. data/lib/tapioca/dsl/compilers/active_record_store.rb +4 -2
  38. data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +18 -26
  39. data/lib/tapioca/dsl/compilers/active_resource.rb +18 -19
  40. data/lib/tapioca/dsl/compilers/active_storage.rb +5 -5
  41. data/lib/tapioca/dsl/compilers/active_support_concern.rb +8 -6
  42. data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +7 -5
  43. data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +4 -2
  44. data/lib/tapioca/dsl/compilers/config.rb +4 -2
  45. data/lib/tapioca/dsl/compilers/frozen_record.rb +6 -9
  46. data/lib/tapioca/dsl/compilers/graphql_input_object.rb +8 -8
  47. data/lib/tapioca/dsl/compilers/graphql_mutation.rb +5 -8
  48. data/lib/tapioca/dsl/compilers/identity_cache.rb +10 -37
  49. data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +8 -16
  50. data/lib/tapioca/dsl/compilers/kredis.rb +6 -4
  51. data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +4 -2
  52. data/lib/tapioca/dsl/compilers/protobuf.rb +12 -24
  53. data/lib/tapioca/dsl/compilers/rails_generators.rb +8 -9
  54. data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +22 -11
  55. data/lib/tapioca/dsl/compilers/smart_properties.rb +11 -20
  56. data/lib/tapioca/dsl/compilers/state_machines.rb +14 -24
  57. data/lib/tapioca/dsl/compilers/url_helpers.rb +9 -7
  58. data/lib/tapioca/dsl/compilers.rb +4 -7
  59. data/lib/tapioca/dsl/helpers/active_model_type_helper.rb +13 -16
  60. data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +13 -28
  61. data/lib/tapioca/dsl/helpers/active_record_constants_helper.rb +19 -15
  62. data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +5 -24
  63. data/lib/tapioca/dsl/pipeline.rb +30 -58
  64. data/lib/tapioca/executor.rb +6 -12
  65. data/lib/tapioca/gem/events.rb +22 -28
  66. data/lib/tapioca/gem/listeners/base.rb +6 -6
  67. data/lib/tapioca/gem/listeners/dynamic_mixins.rb +4 -2
  68. data/lib/tapioca/gem/listeners/foreign_constants.rb +5 -7
  69. data/lib/tapioca/gem/listeners/methods.rb +15 -34
  70. data/lib/tapioca/gem/listeners/mixins.rb +6 -18
  71. data/lib/tapioca/gem/listeners/remove_empty_payload_scopes.rb +4 -2
  72. data/lib/tapioca/gem/listeners/sorbet_enums.rb +4 -2
  73. data/lib/tapioca/gem/listeners/sorbet_helpers.rb +4 -2
  74. data/lib/tapioca/gem/listeners/sorbet_props.rb +4 -2
  75. data/lib/tapioca/gem/listeners/sorbet_required_ancestors.rb +4 -2
  76. data/lib/tapioca/gem/listeners/sorbet_signatures.rb +7 -5
  77. data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +6 -4
  78. data/lib/tapioca/gem/listeners/source_location.rb +7 -4
  79. data/lib/tapioca/gem/listeners/subconstants.rb +5 -4
  80. data/lib/tapioca/gem/listeners/yard_doc.rb +23 -22
  81. data/lib/tapioca/gem/pipeline.rb +57 -72
  82. data/lib/tapioca/gem_info.rb +1 -1
  83. data/lib/tapioca/gemfile.rb +64 -73
  84. data/lib/tapioca/helpers/cli_helper.rb +3 -3
  85. data/lib/tapioca/helpers/config_helper.rb +15 -24
  86. data/lib/tapioca/helpers/env_helper.rb +1 -1
  87. data/lib/tapioca/helpers/gem_helper.rb +5 -5
  88. data/lib/tapioca/helpers/git_attributes.rb +3 -3
  89. data/lib/tapioca/helpers/rbi_files_helper.rb +73 -67
  90. data/lib/tapioca/helpers/rbi_helper.rb +14 -22
  91. data/lib/tapioca/helpers/sorbet_helper.rb +9 -18
  92. data/lib/tapioca/helpers/source_uri.rb +15 -25
  93. data/lib/tapioca/helpers/test/content.rb +6 -6
  94. data/lib/tapioca/helpers/test/dsl_compiler.rb +19 -29
  95. data/lib/tapioca/helpers/test/isolation.rb +4 -4
  96. data/lib/tapioca/helpers/test/template.rb +5 -7
  97. data/lib/tapioca/internal.rb +5 -1
  98. data/lib/tapioca/loaders/dsl.rb +11 -19
  99. data/lib/tapioca/loaders/gem.rb +6 -21
  100. data/lib/tapioca/loaders/loader.rb +15 -27
  101. data/lib/tapioca/rbi_ext/model.rb +12 -37
  102. data/lib/tapioca/rbi_formatter.rb +10 -19
  103. data/lib/tapioca/rbs/rewriter.rb +55 -0
  104. data/lib/tapioca/repo_index.rb +7 -7
  105. data/lib/tapioca/runtime/attached_class_of_32.rb +1 -1
  106. data/lib/tapioca/runtime/attached_class_of_legacy.rb +1 -1
  107. data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +23 -23
  108. data/lib/tapioca/runtime/generic_type_registry.rb +13 -23
  109. data/lib/tapioca/runtime/reflection.rb +48 -56
  110. data/lib/tapioca/runtime/trackers/autoload.rb +4 -8
  111. data/lib/tapioca/runtime/trackers/mixin.rb +6 -10
  112. data/lib/tapioca/runtime/trackers/required_ancestor.rb +3 -3
  113. data/lib/tapioca/runtime/trackers/tracker.rb +2 -2
  114. data/lib/tapioca/runtime/trackers.rb +4 -8
  115. data/lib/tapioca/sorbet_ext/generic_name_patch.rb +9 -15
  116. data/lib/tapioca/sorbet_ext/name_patch.rb +1 -1
  117. data/lib/tapioca/sorbet_ext/proc_bind_patch.rb +1 -1
  118. data/lib/tapioca/static/requires_compiler.rb +6 -6
  119. data/lib/tapioca/static/symbol_loader.rb +14 -16
  120. data/lib/tapioca/static/symbol_table_parser.rb +8 -8
  121. data/lib/tapioca/version.rb +1 -1
  122. data/lib/tapioca.rb +22 -29
  123. metadata +25 -10
@@ -156,25 +156,23 @@ module Tapioca
156
156
  ConstantType = type_member { { fixed: T.class_of(::ActiveRecord::Base) } }
157
157
 
158
158
  # From ActiveRecord::ConnectionAdapter::Quoting#quote, minus nil
159
- ID_TYPES = T.let(
160
- [
161
- "String",
162
- "Symbol",
163
- "::ActiveSupport::Multibyte::Chars",
164
- "T::Boolean",
165
- "BigDecimal",
166
- "Numeric",
167
- "::ActiveRecord::Type::Binary::Data",
168
- "::ActiveRecord::Type::Time::Value",
169
- "Date",
170
- "Time",
171
- "::ActiveSupport::Duration",
172
- "T::Class[T.anything]",
173
- ].to_set.freeze,
174
- T::Set[String],
175
- )
176
-
177
- sig { override.void }
159
+ ID_TYPES = [
160
+ "String",
161
+ "Symbol",
162
+ "::ActiveSupport::Multibyte::Chars",
163
+ "T::Boolean",
164
+ "BigDecimal",
165
+ "Numeric",
166
+ "::ActiveRecord::Type::Binary::Data",
167
+ "::ActiveRecord::Type::Time::Value",
168
+ "Date",
169
+ "Time",
170
+ "::ActiveSupport::Duration",
171
+ "T::Class[T.anything]",
172
+ ].to_set.freeze #: Set[String]
173
+
174
+ # @override
175
+ #: -> void
178
176
  def decorate
179
177
  create_classes_and_includes
180
178
  create_common_methods
@@ -185,104 +183,86 @@ module Tapioca
185
183
  class << self
186
184
  extend T::Sig
187
185
 
188
- sig { override.returns(T::Enumerable[Module]) }
186
+ # @override
187
+ #: -> T::Enumerable[Module]
189
188
  def gather_constants
190
189
  ActiveRecord::Base.descendants.reject(&:abstract_class?)
191
190
  end
192
191
  end
193
192
 
194
- ASSOCIATION_METHODS = T.let(
195
- ::ActiveRecord::AssociationRelation.instance_methods -
196
- ::ActiveRecord::Relation.instance_methods,
197
- T::Array[Symbol],
198
- )
199
- COLLECTION_PROXY_METHODS = T.let(
200
- ::ActiveRecord::Associations::CollectionProxy.instance_methods -
201
- ::ActiveRecord::AssociationRelation.instance_methods,
202
- T::Array[Symbol],
203
- )
204
-
205
- QUERY_METHODS = T.let(
206
- begin
207
- # Grab all Query methods
208
- query_methods = ActiveRecord::QueryMethods.instance_methods(false)
209
- # Grab all Spawn methods
210
- query_methods |= ActiveRecord::SpawnMethods.instance_methods(false)
211
- # Remove the ones we know are private API
212
- query_methods -= [:all, :arel, :build_subquery, :construct_join_dependency, :extensions, :spawn]
213
- # Remove the methods that ...
214
- query_methods
215
- .grep_v(/_clause$/) # end with "_clause"
216
- .grep_v(/_values?$/) # end with "_value" or "_values"
217
- .grep_v(/=$/) # end with "=""
218
- .grep_v(/(?<!uniq)!$/) # end with "!" except for "uniq!"
219
- end,
220
- T::Array[Symbol],
221
- )
222
- WHERE_CHAIN_QUERY_METHODS = T.let(
223
- ActiveRecord::QueryMethods::WhereChain.instance_methods(false),
224
- T::Array[Symbol],
225
- )
226
- FINDER_METHODS = T.let(ActiveRecord::FinderMethods.instance_methods(false), T::Array[Symbol])
227
- SIGNED_FINDER_METHODS = T.let(
228
- defined?(ActiveRecord::SignedId) ? ActiveRecord::SignedId::ClassMethods.instance_methods(false) : [],
229
- T::Array[Symbol],
230
- )
231
- BATCHES_METHODS = T.let(ActiveRecord::Batches.instance_methods(false), T::Array[Symbol])
232
- CALCULATION_METHODS = T.let(ActiveRecord::Calculations.instance_methods(false), T::Array[Symbol])
233
- ENUMERABLE_QUERY_METHODS = T.let([:any?, :many?, :none?, :one?], T::Array[Symbol])
234
- FIND_OR_CREATE_METHODS = T.let(
235
- [:find_or_create_by, :find_or_create_by!, :find_or_initialize_by, :create_or_find_by, :create_or_find_by!],
236
- T::Array[Symbol],
237
- )
238
- BUILDER_METHODS = T.let([:new, :create, :create!, :build], T::Array[Symbol])
239
- TO_ARRAY_METHODS = T.let([:to_ary, :to_a], T::Array[Symbol])
193
+ ASSOCIATION_METHODS = ::ActiveRecord::AssociationRelation.instance_methods -
194
+ ::ActiveRecord::Relation.instance_methods #: Array[Symbol]
195
+ COLLECTION_PROXY_METHODS = ::ActiveRecord::Associations::CollectionProxy.instance_methods -
196
+ ::ActiveRecord::AssociationRelation.instance_methods #: Array[Symbol]
197
+
198
+ QUERY_METHODS = begin
199
+ # Grab all Query methods
200
+ query_methods = ActiveRecord::QueryMethods.instance_methods(false)
201
+ # Grab all Spawn methods
202
+ query_methods |= ActiveRecord::SpawnMethods.instance_methods(false)
203
+ # Remove the ones we know are private API
204
+ query_methods -= [:all, :arel, :build_subquery, :construct_join_dependency, :extensions, :spawn]
205
+ # Remove the methods that ...
206
+ query_methods
207
+ .grep_v(/_clause$/) # end with "_clause"
208
+ .grep_v(/_values?$/) # end with "_value" or "_values"
209
+ .grep_v(/=$/) # end with "=""
210
+ .grep_v(/(?<!uniq)!$/) # end with "!" except for "uniq!"
211
+ end #: Array[Symbol]
212
+ WHERE_CHAIN_QUERY_METHODS = ActiveRecord::QueryMethods::WhereChain.instance_methods(false) #: Array[Symbol]
213
+ FINDER_METHODS = ActiveRecord::FinderMethods.instance_methods(false) #: Array[Symbol]
214
+ SIGNED_FINDER_METHODS = if defined?(ActiveRecord::SignedId)
215
+ ActiveRecord::SignedId::ClassMethods.instance_methods(false)
216
+ else
217
+ []
218
+ end #: Array[Symbol]
219
+ BATCHES_METHODS = ActiveRecord::Batches.instance_methods(false) #: Array[Symbol]
220
+ CALCULATION_METHODS = ActiveRecord::Calculations.instance_methods(false) #: Array[Symbol]
221
+ ENUMERABLE_QUERY_METHODS = [:any?, :many?, :none?, :one?] #: Array[Symbol]
222
+ FIND_OR_CREATE_METHODS = [
223
+ :find_or_create_by,
224
+ :find_or_create_by!,
225
+ :find_or_initialize_by,
226
+ :create_or_find_by,
227
+ :create_or_find_by!,
228
+ ] #: Array[Symbol]
229
+ BUILDER_METHODS = [:new, :create, :create!, :build] #: Array[Symbol]
230
+ TO_ARRAY_METHODS = [:to_ary, :to_a] #: Array[Symbol]
240
231
 
241
232
  private
242
233
 
243
- sig { returns(RBI::Scope) }
234
+ #: -> RBI::Scope
244
235
  def model
245
- @model ||= T.let(
246
- root.create_path(constant),
247
- T.nilable(RBI::Scope),
248
- )
236
+ @model ||= root.create_path(constant) #: RBI::Scope?
249
237
  end
250
238
 
251
- sig { returns(RBI::Scope) }
239
+ #: -> RBI::Scope
252
240
  def relation_methods_module
253
- @relation_methods_module ||= T.let(
254
- model.create_module(RelationMethodsModuleName),
255
- T.nilable(RBI::Scope),
256
- )
241
+ @relation_methods_module ||= model.create_module(RelationMethodsModuleName) #: RBI::Scope?
257
242
  end
258
243
 
259
- sig { returns(RBI::Scope) }
244
+ #: -> RBI::Scope
260
245
  def association_relation_methods_module
261
- @association_relation_methods_module ||= T.let(
262
- model.create_module(AssociationRelationMethodsModuleName),
263
- T.nilable(RBI::Scope),
264
- )
246
+ @association_relation_methods_module ||=
247
+ model.create_module(AssociationRelationMethodsModuleName) #: RBI::Scope?
265
248
  end
266
249
 
267
- sig { returns(RBI::Scope) }
250
+ #: -> RBI::Scope
268
251
  def common_relation_methods_module
269
- @common_relation_methods_module ||= T.let(
270
- model.create_module(CommonRelationMethodsModuleName),
271
- T.nilable(RBI::Scope),
272
- )
252
+ @common_relation_methods_module ||= model.create_module(CommonRelationMethodsModuleName) #: RBI::Scope?
273
253
  end
274
254
 
275
- sig { returns(String) }
255
+ #: -> String
276
256
  def constant_name
277
- @constant_name ||= T.let(T.must(qualified_name_of(constant)), T.nilable(String))
257
+ @constant_name ||= T.must(qualified_name_of(constant)) #: String?
278
258
  end
279
259
 
280
- sig { params(method_name: Symbol).returns(T::Boolean) }
260
+ #: (Symbol method_name) -> bool
281
261
  def bang_method?(method_name)
282
262
  method_name.to_s.end_with?("!")
283
263
  end
284
264
 
285
- sig { void }
265
+ #: -> void
286
266
  def create_classes_and_includes
287
267
  model.create_extend(CommonRelationMethodsModuleName)
288
268
  # The model always extends the generated relation module
@@ -297,7 +277,7 @@ module Tapioca
297
277
  create_collection_proxy_class
298
278
  end
299
279
 
300
- sig { void }
280
+ #: -> void
301
281
  def create_relation_class
302
282
  superclass = "::ActiveRecord::Relation"
303
283
 
@@ -316,7 +296,7 @@ module Tapioca
316
296
  create_relation_where_chain_class
317
297
  end
318
298
 
319
- sig { void }
299
+ #: -> void
320
300
  def create_association_relation_class
321
301
  superclass = "::ActiveRecord::AssociationRelation"
322
302
 
@@ -335,7 +315,7 @@ module Tapioca
335
315
  create_association_relation_where_chain_class
336
316
  end
337
317
 
338
- sig { void }
318
+ #: -> void
339
319
  def create_relation_group_chain_class
340
320
  model.create_class(RelationGroupChainClassName, superclass_name: RelationClassName) do |klass|
341
321
  create_group_chain_methods(klass)
@@ -343,7 +323,7 @@ module Tapioca
343
323
  end
344
324
  end
345
325
 
346
- sig { void }
326
+ #: -> void
347
327
  def create_association_relation_group_chain_class
348
328
  model.create_class(
349
329
  AssociationRelationGroupChainClassName,
@@ -354,7 +334,7 @@ module Tapioca
354
334
  end
355
335
  end
356
336
 
357
- sig { params(klass: RBI::Scope).void }
337
+ #: (RBI::Scope klass) -> void
358
338
  def create_group_chain_methods(klass)
359
339
  # Calculation methods used with `group` return a hash where the keys cannot be typed
360
340
  # but the values can. Technically a `group` anywhere in the query chain produces
@@ -418,7 +398,7 @@ module Tapioca
418
398
  end
419
399
  end
420
400
 
421
- sig { void }
401
+ #: -> void
422
402
  def create_relation_where_chain_class
423
403
  model.create_class(RelationWhereChainClassName) do |klass|
424
404
  create_where_chain_methods(klass, RelationClassName)
@@ -426,7 +406,7 @@ module Tapioca
426
406
  end
427
407
  end
428
408
 
429
- sig { void }
409
+ #: -> void
430
410
  def create_association_relation_where_chain_class
431
411
  model.create_class(AssociationRelationWhereChainClassName) do |klass|
432
412
  create_where_chain_methods(klass, AssociationRelationClassName)
@@ -434,7 +414,7 @@ module Tapioca
434
414
  end
435
415
  end
436
416
 
437
- sig { params(klass: RBI::Scope, return_type: String).void }
417
+ #: (RBI::Scope klass, String return_type) -> void
438
418
  def create_where_chain_methods(klass, return_type)
439
419
  WHERE_CHAIN_QUERY_METHODS.each do |method_name|
440
420
  case method_name
@@ -459,7 +439,7 @@ module Tapioca
459
439
  end
460
440
  end
461
441
 
462
- sig { void }
442
+ #: -> void
463
443
  def create_collection_proxy_class
464
444
  superclass = "::ActiveRecord::Associations::CollectionProxy"
465
445
 
@@ -476,7 +456,7 @@ module Tapioca
476
456
  end
477
457
  end
478
458
 
479
- sig { params(klass: RBI::Scope).void }
459
+ #: (RBI::Scope klass) -> void
480
460
  def create_collection_proxy_methods(klass)
481
461
  # For these cases, it is valid to pass:
482
462
  # - a model instance, thus `Model`
@@ -555,7 +535,7 @@ module Tapioca
555
535
  end
556
536
  end
557
537
 
558
- sig { void }
538
+ #: -> void
559
539
  def create_relation_methods
560
540
  create_relation_method("all")
561
541
 
@@ -619,7 +599,7 @@ module Tapioca
619
599
  end
620
600
  end
621
601
 
622
- sig { void }
602
+ #: -> void
623
603
  def create_association_relation_methods
624
604
  returning_type = "T.nilable(T.any(T::Array[Symbol], FalseClass))"
625
605
  unique_by_type = "T.nilable(T.any(T::Array[Symbol], Symbol))"
@@ -664,7 +644,7 @@ module Tapioca
664
644
  end
665
645
  end
666
646
 
667
- sig { void }
647
+ #: -> void
668
648
  def create_common_methods
669
649
  create_common_method(
670
650
  "destroy_all",
@@ -1049,13 +1029,7 @@ module Tapioca
1049
1029
  end
1050
1030
  end
1051
1031
 
1052
- sig do
1053
- params(
1054
- name: T.any(Symbol, String),
1055
- parameters: T::Array[RBI::TypedParam],
1056
- return_type: T.nilable(String),
1057
- ).void
1058
- end
1032
+ #: ((Symbol | String) name, ?parameters: Array[RBI::TypedParam], ?return_type: String?) -> void
1059
1033
  def create_common_method(name, parameters: [], return_type: nil)
1060
1034
  common_relation_methods_module.create_method(
1061
1035
  name.to_s,
@@ -1064,7 +1038,7 @@ module Tapioca
1064
1038
  )
1065
1039
  end
1066
1040
 
1067
- sig { void }
1041
+ #: -> void
1068
1042
  def create_where_relation_method
1069
1043
  relation_methods_module.create_method("where") do |method|
1070
1044
  method.add_rest_param("args")
@@ -1093,14 +1067,7 @@ module Tapioca
1093
1067
  end
1094
1068
  end
1095
1069
 
1096
- sig do
1097
- params(
1098
- name: T.any(Symbol, String),
1099
- parameters: T::Array[RBI::TypedParam],
1100
- relation_return_type: String,
1101
- association_return_type: String,
1102
- ).void
1103
- end
1070
+ #: ((Symbol | String) name, ?parameters: Array[RBI::TypedParam], ?relation_return_type: String, ?association_return_type: String) -> void
1104
1071
  def create_relation_method(
1105
1072
  name,
1106
1073
  parameters: [],
@@ -44,7 +44,8 @@ module Tapioca
44
44
 
45
45
  ConstantType = type_member { { fixed: T.class_of(::ActiveRecord::Base) } }
46
46
 
47
- sig { override.void }
47
+ # @override
48
+ #: -> void
48
49
  def decorate
49
50
  method_names = scope_method_names
50
51
 
@@ -77,7 +78,8 @@ module Tapioca
77
78
  end
78
79
 
79
80
  class << self
80
- sig { override.returns(T::Enumerable[Module]) }
81
+ # @override
82
+ #: -> T::Enumerable[Module]
81
83
  def gather_constants
82
84
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
83
85
  end
@@ -85,9 +87,9 @@ module Tapioca
85
87
 
86
88
  private
87
89
 
88
- sig { returns(T::Array[Symbol]) }
90
+ #: -> Array[Symbol]
89
91
  def scope_method_names
90
- scope_methods = T.let([], T::Array[Symbol])
92
+ scope_methods = [] #: Array[Symbol]
91
93
  constant = self.constant
92
94
 
93
95
  # Keep gathering scope methods until we hit "ActiveRecord::Base"
@@ -104,13 +106,7 @@ module Tapioca
104
106
  scope_methods.uniq
105
107
  end
106
108
 
107
- sig do
108
- params(
109
- mod: RBI::Scope,
110
- scope_method: String,
111
- return_type: String,
112
- ).void
113
- end
109
+ #: (RBI::Scope mod, String scope_method, String return_type) -> void
114
110
  def generate_scope_method(mod, scope_method, return_type)
115
111
  mod.create_method(
116
112
  scope_method,
@@ -38,7 +38,8 @@ module Tapioca
38
38
 
39
39
  ConstantType = type_member { { fixed: T.all(T.class_of(ActiveRecord::Base), Extensions::ActiveRecord) } }
40
40
 
41
- sig { override.void }
41
+ # @override
42
+ #: -> void
42
43
  def decorate
43
44
  return if constant.__tapioca_secure_tokens.nil?
44
45
 
@@ -59,7 +60,8 @@ module Tapioca
59
60
  class << self
60
61
  extend T::Sig
61
62
 
62
- sig { override.returns(T::Enumerable[Module]) }
63
+ # @override
64
+ #: -> T::Enumerable[Module]
63
65
  def gather_constants
64
66
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
65
67
  end
@@ -84,7 +84,8 @@ module Tapioca
84
84
 
85
85
  ConstantType = type_member { { fixed: T.all(T.class_of(ActiveRecord::Base), Extensions::ActiveRecord) } }
86
86
 
87
- sig { override.void }
87
+ # @override
88
+ #: -> void
88
89
  def decorate
89
90
  return if constant.__tapioca_stored_attributes.nil?
90
91
 
@@ -134,7 +135,8 @@ module Tapioca
134
135
  class << self
135
136
  extend T::Sig
136
137
 
137
- sig { override.returns(T::Enumerable[Module]) }
138
+ # @override
139
+ #: -> T::Enumerable[Module]
138
140
  def gather_constants
139
141
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
140
142
  end
@@ -86,7 +86,8 @@ module Tapioca
86
86
 
87
87
  ConstantType = type_member { { fixed: T.class_of(::ActiveRecord::Base) } }
88
88
 
89
- sig { override.void }
89
+ # @override
90
+ #: -> void
90
91
  def decorate
91
92
  stores = constant.typed_stores
92
93
  return if stores.values.all? { |store| store.accessors.empty? }
@@ -110,7 +111,8 @@ module Tapioca
110
111
  class << self
111
112
  extend T::Sig
112
113
 
113
- sig { override.returns(T::Enumerable[Module]) }
114
+ # @override
115
+ #: -> T::Enumerable[Module]
114
116
  def gather_constants
115
117
  descendants_of(::ActiveRecord::Base).select do |klass|
116
118
  klass.include?(ActiveRecord::TypedStore::Behavior)
@@ -120,22 +122,19 @@ module Tapioca
120
122
 
121
123
  private
122
124
 
123
- TYPES = T.let(
124
- {
125
- boolean: "T::Boolean",
126
- integer: "Integer",
127
- string: "String",
128
- float: "Float",
129
- date: "Date",
130
- time: "Time",
131
- datetime: "DateTime",
132
- decimal: "BigDecimal",
133
- any: "T.untyped",
134
- }.freeze,
135
- T::Hash[Symbol, String],
136
- )
137
-
138
- sig { params(field: ActiveRecord::TypedStore::Field).returns(String) }
125
+ TYPES = {
126
+ boolean: "T::Boolean",
127
+ integer: "Integer",
128
+ string: "String",
129
+ float: "Float",
130
+ date: "Date",
131
+ time: "Time",
132
+ datetime: "DateTime",
133
+ decimal: "BigDecimal",
134
+ any: "T.untyped",
135
+ }.freeze #: Hash[Symbol, String]
136
+
137
+ #: (ActiveRecord::TypedStore::Field field) -> String
139
138
  def type_for(field)
140
139
  type = TYPES.fetch(field.type_sym, "T.untyped")
141
140
 
@@ -154,14 +153,7 @@ module Tapioca
154
153
  type
155
154
  end
156
155
 
157
- sig do
158
- params(
159
- klass: RBI::Scope,
160
- name: String,
161
- type: String,
162
- )
163
- .void
164
- end
156
+ #: (RBI::Scope klass, String name, String type) -> void
165
157
  def generate_methods(klass, name, type)
166
158
  klass.create_method(
167
159
  "#{name}=",
@@ -59,7 +59,8 @@ module Tapioca
59
59
 
60
60
  ConstantType = type_member { { fixed: T.class_of(::ActiveResource::Base) } }
61
61
 
62
- sig { override.void }
62
+ # @override
63
+ #: -> void
63
64
  def decorate
64
65
  return if constant.schema.blank?
65
66
 
@@ -73,7 +74,8 @@ module Tapioca
73
74
  class << self
74
75
  extend T::Sig
75
76
 
76
- sig { override.returns(T::Enumerable[Module]) }
77
+ # @override
78
+ #: -> T::Enumerable[Module]
77
79
  def gather_constants
78
80
  descendants_of(::ActiveResource::Base)
79
81
  end
@@ -81,28 +83,25 @@ module Tapioca
81
83
 
82
84
  private
83
85
 
84
- TYPES = T.let(
85
- {
86
- boolean: "T::Boolean",
87
- integer: "Integer",
88
- string: "String",
89
- float: "Float",
90
- date: "Date",
91
- time: "Time",
92
- datetime: "DateTime",
93
- decimal: "BigDecimal",
94
- binary: "String",
95
- text: "String",
96
- }.freeze,
97
- T::Hash[Symbol, String],
98
- )
86
+ TYPES = {
87
+ boolean: "T::Boolean",
88
+ integer: "Integer",
89
+ string: "String",
90
+ float: "Float",
91
+ date: "Date",
92
+ time: "Time",
93
+ datetime: "DateTime",
94
+ decimal: "BigDecimal",
95
+ binary: "String",
96
+ text: "String",
97
+ }.freeze #: Hash[Symbol, String]
99
98
 
100
- sig { params(attr_type: Symbol).returns(String) }
99
+ #: (Symbol attr_type) -> String
101
100
  def type_for(attr_type)
102
101
  TYPES.fetch(attr_type, "T.untyped")
103
102
  end
104
103
 
105
- sig { params(klass: RBI::Scope, attribute: String, type: String).void }
104
+ #: (RBI::Scope klass, String attribute, String type) -> void
106
105
  def create_schema_methods(klass, attribute, type)
107
106
  return_type = type_for(type.to_sym)
108
107
 
@@ -50,7 +50,8 @@ module Tapioca
50
50
  }
51
51
  end
52
52
 
53
- sig { override.void }
53
+ # @override
54
+ #: -> void
54
55
  def decorate
55
56
  return if constant.reflect_on_all_attachments.empty?
56
57
 
@@ -74,7 +75,8 @@ module Tapioca
74
75
  class << self
75
76
  extend T::Sig
76
77
 
77
- sig { override.returns(T::Enumerable[Module]) }
78
+ # @override
79
+ #: -> T::Enumerable[Module]
78
80
  def gather_constants
79
81
  descendants_of(::ActiveRecord::Base)
80
82
  .reject(&:abstract_class?)
@@ -84,9 +86,7 @@ module Tapioca
84
86
 
85
87
  private
86
88
 
87
- sig do
88
- params(reflection: ActiveRecord::Reflection::MacroReflection).returns(String)
89
- end
89
+ #: (ActiveRecord::Reflection::MacroReflection reflection) -> String
90
90
  def type_of(reflection)
91
91
  case reflection
92
92
  when ::ActiveStorage::Reflection::HasOneAttachedReflection
@@ -42,7 +42,8 @@ module Tapioca
42
42
 
43
43
  ConstantType = type_member { { fixed: Module } }
44
44
 
45
- sig { override.void }
45
+ # @override
46
+ #: -> void
46
47
  def decorate
47
48
  dependencies = linearized_dependencies
48
49
 
@@ -64,7 +65,8 @@ module Tapioca
64
65
  class << self
65
66
  extend T::Sig
66
67
 
67
- sig { override.returns(T::Enumerable[Module]) }
68
+ # @override
69
+ #: -> T::Enumerable[Module]
68
70
  def gather_constants
69
71
  all_modules.select do |mod|
70
72
  name_of(mod) && # i.e. not anonymous
@@ -75,10 +77,10 @@ module Tapioca
75
77
  end
76
78
 
77
79
  # Returns true when `mod` includes other concerns
78
- sig { params(mod: Module).returns(T::Boolean) }
80
+ #: (Module mod) -> bool
79
81
  def has_dependencies?(mod) = dependencies_of(mod).any?
80
82
 
81
- sig { params(concern: Module).returns(T::Array[Module]) }
83
+ #: (Module concern) -> Array[Module]
82
84
  def dependencies_of(concern)
83
85
  concern.instance_variable_get(:@_dependencies) || []
84
86
  end
@@ -86,12 +88,12 @@ module Tapioca
86
88
 
87
89
  private
88
90
 
89
- sig { params(concern: Module).returns(T::Array[Module]) }
91
+ #: (Module concern) -> Array[Module]
90
92
  def dependencies_of(concern)
91
93
  self.class.dependencies_of(concern)
92
94
  end
93
95
 
94
- sig { params(concern: Module).returns(T::Array[Module]) }
96
+ #: (?Module concern) -> Array[Module]
95
97
  def linearized_dependencies(concern = constant)
96
98
  # Grab all the dependencies of the concern
97
99
  dependencies = dependencies_of(concern)