tapioca 0.16.9 → 0.17.7

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 (130) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -0
  3. data/exe/tapioca +6 -1
  4. data/lib/ruby_lsp/tapioca/addon.rb +73 -43
  5. data/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb +43 -43
  6. data/lib/ruby_lsp/tapioca/server_addon.rb +13 -10
  7. data/lib/tapioca/bundler_ext/auto_require_hook.rb +6 -14
  8. data/lib/tapioca/cli.rb +16 -8
  9. data/lib/tapioca/commands/abstract_dsl.rb +39 -66
  10. data/lib/tapioca/commands/abstract_gem.rb +25 -46
  11. data/lib/tapioca/commands/annotations.rb +28 -34
  12. data/lib/tapioca/commands/check_shims.rb +6 -15
  13. data/lib/tapioca/commands/command.rb +12 -26
  14. data/lib/tapioca/commands/command_without_tracker.rb +2 -5
  15. data/lib/tapioca/commands/configure.rb +11 -16
  16. data/lib/tapioca/commands/dsl_compiler_list.rb +2 -1
  17. data/lib/tapioca/commands/dsl_generate.rb +2 -1
  18. data/lib/tapioca/commands/dsl_verify.rb +2 -1
  19. data/lib/tapioca/commands/gem_generate.rb +5 -9
  20. data/lib/tapioca/commands/gem_sync.rb +2 -1
  21. data/lib/tapioca/commands/gem_verify.rb +3 -2
  22. data/lib/tapioca/commands/require.rb +3 -7
  23. data/lib/tapioca/commands/todo.rb +6 -10
  24. data/lib/tapioca/dsl/compiler.rb +36 -63
  25. data/lib/tapioca/dsl/compilers/aasm.rb +33 -44
  26. data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +8 -7
  27. data/lib/tapioca/dsl/compilers/action_mailer.rb +6 -5
  28. data/lib/tapioca/dsl/compilers/action_text.rb +6 -5
  29. data/lib/tapioca/dsl/compilers/active_job.rb +6 -10
  30. data/lib/tapioca/dsl/compilers/active_model_attributes.rb +10 -11
  31. data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +5 -6
  32. data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +5 -12
  33. data/lib/tapioca/dsl/compilers/active_record_associations.rb +17 -44
  34. data/lib/tapioca/dsl/compilers/active_record_columns.rb +20 -26
  35. data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +9 -8
  36. data/lib/tapioca/dsl/compilers/active_record_enum.rb +7 -6
  37. data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +54 -62
  38. data/lib/tapioca/dsl/compilers/active_record_relations.rb +148 -209
  39. data/lib/tapioca/dsl/compilers/active_record_scope.rb +8 -13
  40. data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +5 -4
  41. data/lib/tapioca/dsl/compilers/active_record_store.rb +5 -4
  42. data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +19 -28
  43. data/lib/tapioca/dsl/compilers/active_resource.rb +19 -21
  44. data/lib/tapioca/dsl/compilers/active_storage.rb +6 -14
  45. data/lib/tapioca/dsl/compilers/active_support_concern.rb +9 -8
  46. data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +8 -7
  47. data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +5 -4
  48. data/lib/tapioca/dsl/compilers/config.rb +5 -4
  49. data/lib/tapioca/dsl/compilers/frozen_record.rb +7 -11
  50. data/lib/tapioca/dsl/compilers/graphql_input_object.rb +9 -10
  51. data/lib/tapioca/dsl/compilers/graphql_mutation.rb +6 -10
  52. data/lib/tapioca/dsl/compilers/identity_cache.rb +11 -39
  53. data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +9 -18
  54. data/lib/tapioca/dsl/compilers/kredis.rb +7 -8
  55. data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +5 -4
  56. data/lib/tapioca/dsl/compilers/protobuf.rb +13 -26
  57. data/lib/tapioca/dsl/compilers/rails_generators.rb +9 -11
  58. data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +23 -13
  59. data/lib/tapioca/dsl/compilers/smart_properties.rb +32 -38
  60. data/lib/tapioca/dsl/compilers/state_machines.rb +15 -26
  61. data/lib/tapioca/dsl/compilers/url_helpers.rb +10 -9
  62. data/lib/tapioca/dsl/compilers.rb +4 -7
  63. data/lib/tapioca/dsl/helpers/active_model_type_helper.rb +13 -16
  64. data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +13 -28
  65. data/lib/tapioca/dsl/helpers/active_record_constants_helper.rb +19 -15
  66. data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +5 -24
  67. data/lib/tapioca/dsl/pipeline.rb +30 -58
  68. data/lib/tapioca/executor.rb +6 -12
  69. data/lib/tapioca/gem/events.rb +24 -34
  70. data/lib/tapioca/gem/listeners/base.rb +7 -10
  71. data/lib/tapioca/gem/listeners/dynamic_mixins.rb +4 -2
  72. data/lib/tapioca/gem/listeners/foreign_constants.rb +5 -7
  73. data/lib/tapioca/gem/listeners/methods.rb +36 -47
  74. data/lib/tapioca/gem/listeners/mixins.rb +6 -18
  75. data/lib/tapioca/gem/listeners/remove_empty_payload_scopes.rb +4 -2
  76. data/lib/tapioca/gem/listeners/sorbet_enums.rb +4 -2
  77. data/lib/tapioca/gem/listeners/sorbet_helpers.rb +4 -2
  78. data/lib/tapioca/gem/listeners/sorbet_props.rb +4 -2
  79. data/lib/tapioca/gem/listeners/sorbet_required_ancestors.rb +4 -2
  80. data/lib/tapioca/gem/listeners/sorbet_signatures.rb +7 -5
  81. data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +6 -4
  82. data/lib/tapioca/gem/listeners/source_location.rb +15 -8
  83. data/lib/tapioca/gem/listeners/subconstants.rb +5 -4
  84. data/lib/tapioca/gem/listeners/yard_doc.rb +30 -23
  85. data/lib/tapioca/gem/pipeline.rb +107 -91
  86. data/lib/tapioca/gem_info.rb +1 -1
  87. data/lib/tapioca/gemfile.rb +64 -73
  88. data/lib/tapioca/helpers/cli_helper.rb +4 -7
  89. data/lib/tapioca/helpers/config_helper.rb +17 -29
  90. data/lib/tapioca/helpers/env_helper.rb +2 -5
  91. data/lib/tapioca/helpers/gem_helper.rb +5 -5
  92. data/lib/tapioca/helpers/git_attributes.rb +3 -3
  93. data/lib/tapioca/helpers/rbi_files_helper.rb +76 -73
  94. data/lib/tapioca/helpers/rbi_helper.rb +14 -22
  95. data/lib/tapioca/helpers/sorbet_helper.rb +9 -18
  96. data/lib/tapioca/helpers/source_uri.rb +15 -25
  97. data/lib/tapioca/helpers/test/content.rb +7 -10
  98. data/lib/tapioca/helpers/test/dsl_compiler.rb +20 -33
  99. data/lib/tapioca/helpers/test/isolation.rb +10 -14
  100. data/lib/tapioca/helpers/test/template.rb +6 -11
  101. data/lib/tapioca/internal.rb +18 -8
  102. data/lib/tapioca/loaders/dsl.rb +11 -19
  103. data/lib/tapioca/loaders/gem.rb +6 -21
  104. data/lib/tapioca/loaders/loader.rb +21 -39
  105. data/lib/tapioca/rbi_ext/model.rb +12 -37
  106. data/lib/tapioca/rbi_formatter.rb +10 -19
  107. data/lib/tapioca/rbs/rewriter.rb +55 -0
  108. data/lib/tapioca/repo_index.rb +7 -9
  109. data/lib/tapioca/runtime/attached_class_of_32.rb +1 -1
  110. data/lib/tapioca/runtime/attached_class_of_legacy.rb +2 -5
  111. data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +23 -23
  112. data/lib/tapioca/runtime/generic_type_registry.rb +13 -23
  113. data/lib/tapioca/runtime/reflection.rb +81 -60
  114. data/lib/tapioca/runtime/source_location.rb +44 -0
  115. data/lib/tapioca/runtime/trackers/autoload.rb +7 -9
  116. data/lib/tapioca/runtime/trackers/constant_definition.rb +18 -14
  117. data/lib/tapioca/runtime/trackers/method_definition.rb +65 -0
  118. data/lib/tapioca/runtime/trackers/mixin.rb +8 -11
  119. data/lib/tapioca/runtime/trackers/required_ancestor.rb +3 -3
  120. data/lib/tapioca/runtime/trackers/tracker.rb +3 -6
  121. data/lib/tapioca/runtime/trackers.rb +5 -8
  122. data/lib/tapioca/sorbet_ext/generic_name_patch.rb +9 -15
  123. data/lib/tapioca/sorbet_ext/name_patch.rb +2 -2
  124. data/lib/tapioca/sorbet_ext/proc_bind_patch.rb +1 -1
  125. data/lib/tapioca/static/requires_compiler.rb +6 -6
  126. data/lib/tapioca/static/symbol_loader.rb +14 -16
  127. data/lib/tapioca/static/symbol_table_parser.rb +8 -8
  128. data/lib/tapioca/version.rb +1 -1
  129. data/lib/tapioca.rb +22 -29
  130. metadata +27 -10
@@ -32,57 +32,45 @@ module Tapioca
32
32
  # sleeping?, running?, cleaning?
33
33
  # run, run!, run_without_validation!, may_run?
34
34
  #
35
+ #: [ConstantType = (Class[::AASM] & ::AASM::ClassMethods)]
35
36
  class AASM < Compiler
36
37
  extend T::Sig
37
38
 
38
39
  # Taken directly from the AASM::Core::Event class, here:
39
40
  # https://github.com/aasm/aasm/blob/0e03746/lib/aasm/core/event.rb#L21-L29
40
- EVENT_CALLBACKS =
41
- T.let(
42
- [
43
- "after",
44
- "after_commit",
45
- "after_transaction",
46
- "before",
47
- "before_transaction",
48
- "ensure",
49
- "error",
50
- "before_success",
51
- "success",
52
- ].freeze,
53
- T::Array[String],
54
- )
41
+ EVENT_CALLBACKS = [
42
+ "after",
43
+ "after_commit",
44
+ "after_transaction",
45
+ "before",
46
+ "before_transaction",
47
+ "ensure",
48
+ "error",
49
+ "before_success",
50
+ "success",
51
+ ].freeze #: Array[String]
55
52
 
56
53
  # Taken directly from the AASM::Base class, here:
57
54
  # https://github.com/aasm/aasm/blob/0e03746a2b86558ee1bf7bd7db873938cbb3b29b/lib/aasm/base.rb#L145-L171
58
- GLOBAL_CALLBACKS =
59
- T.let(
60
- [
61
- "after_all_transitions",
62
- "after_all_transactions",
63
- "before_all_transactions",
64
- "before_all_events",
65
- "after_all_events",
66
- "error_on_all_events",
67
- "ensure_on_all_events",
68
- ].freeze,
69
- T::Array[String],
70
- )
71
-
72
- TRANSITION_CALLBACKS =
73
- T.let(
74
- [
75
- "on_transition",
76
- "guard",
77
- "after",
78
- "success",
79
- ].freeze,
80
- T::Array[String],
81
- )
82
-
83
- ConstantType = type_member { { fixed: T.all(T::Class[::AASM], ::AASM::ClassMethods) } }
84
-
85
- sig { override.void }
55
+ GLOBAL_CALLBACKS = [
56
+ "after_all_transitions",
57
+ "after_all_transactions",
58
+ "before_all_transactions",
59
+ "before_all_events",
60
+ "after_all_events",
61
+ "error_on_all_events",
62
+ "ensure_on_all_events",
63
+ ].freeze #: Array[String]
64
+
65
+ TRANSITION_CALLBACKS = [
66
+ "on_transition",
67
+ "guard",
68
+ "after",
69
+ "success",
70
+ ].freeze #: Array[String]
71
+
72
+ # @override
73
+ #: -> void
86
74
  def decorate
87
75
  state_machine_store = ::AASM::StateMachineStore.fetch(constant)
88
76
  return unless state_machine_store
@@ -214,7 +202,8 @@ module Tapioca
214
202
  class << self
215
203
  extend T::Sig
216
204
 
217
- sig { override.returns(T::Enumerable[Module]) }
205
+ # @override
206
+ #: -> T::Enumerable[Module]
218
207
  def gather_constants
219
208
  T.cast(ObjectSpace.each_object(::AASM::ClassMethods), T::Enumerable[Module])
220
209
  end
@@ -61,12 +61,12 @@ module Tapioca
61
61
  # def helpers; end
62
62
  # end
63
63
  # ~~~
64
+ #: [ConstantType = singleton(::ActionController::Base)]
64
65
  class ActionControllerHelpers < Compiler
65
66
  extend T::Sig
66
67
 
67
- ConstantType = type_member { { fixed: T.class_of(::ActionController::Base) } }
68
-
69
- sig { override.void }
68
+ # @override
69
+ #: -> void
70
70
  def decorate
71
71
  helpers_module = constant._helpers
72
72
  proxied_helper_methods = constant._helper_methods.map(&:to_s).map(&:to_sym)
@@ -120,7 +120,8 @@ module Tapioca
120
120
  class << self
121
121
  extend T::Sig
122
122
 
123
- sig { override.returns(T::Enumerable[Module]) }
123
+ # @override
124
+ #: -> T::Enumerable[Module]
124
125
  def gather_constants
125
126
  descendants_of(::ActionController::Base).select(&:name).select do |klass|
126
127
  klass.const_defined?(:HelperMethods, false)
@@ -130,7 +131,7 @@ module Tapioca
130
131
 
131
132
  private
132
133
 
133
- sig { params(method_name: Symbol).returns(T.nilable(UnboundMethod)) }
134
+ #: (Symbol method_name) -> UnboundMethod?
134
135
  def helper_method_proxy_target(method_name)
135
136
  # Lookup the proxy target method only if it is defined as a public/protected or private method.
136
137
  if constant.method_defined?(method_name) || constant.private_method_defined?(method_name)
@@ -138,7 +139,7 @@ module Tapioca
138
139
  end
139
140
  end
140
141
 
141
- sig { params(helper_methods: RBI::Scope, method_name: Symbol).void }
142
+ #: (RBI::Scope helper_methods, Symbol method_name) -> void
142
143
  def create_unknown_proxy_method(helper_methods, method_name)
143
144
  helper_methods.create_method(
144
145
  method_name.to_s,
@@ -151,7 +152,7 @@ module Tapioca
151
152
  )
152
153
  end
153
154
 
154
- sig { params(mod: Module).returns(T::Array[String]) }
155
+ #: (Module mod) -> Array[String]
155
156
  def gather_includes(mod)
156
157
  mod.ancestors
157
158
  .reject { |ancestor| ancestor.is_a?(Class) || ancestor == mod || name_of(ancestor).nil? }
@@ -29,12 +29,12 @@ module Tapioca
29
29
  # def self.notify_customer(customer_id); end
30
30
  # end
31
31
  # ~~~
32
+ #: [ConstantType = singleton(::ActionMailer::Base)]
32
33
  class ActionMailer < Compiler
33
34
  extend T::Sig
34
35
 
35
- ConstantType = type_member { { fixed: T.class_of(::ActionMailer::Base) } }
36
-
37
- sig { override.void }
36
+ # @override
37
+ #: -> void
38
38
  def decorate
39
39
  root.create_path(constant) do |mailer|
40
40
  action_methods_for_constant.each do |mailer_method|
@@ -53,7 +53,8 @@ module Tapioca
53
53
  class << self
54
54
  extend T::Sig
55
55
 
56
- sig { override.returns(T::Enumerable[Module]) }
56
+ # @override
57
+ #: -> T::Enumerable[Module]
57
58
  def gather_constants
58
59
  descendants_of(::ActionMailer::Base).reject(&:abstract?)
59
60
  end
@@ -61,7 +62,7 @@ module Tapioca
61
62
 
62
63
  private
63
64
 
64
- sig { returns(T::Array[String]) }
65
+ #: -> Array[String]
65
66
  def action_methods_for_constant
66
67
  constant.action_methods.to_a
67
68
  end
@@ -43,12 +43,12 @@ module Tapioca
43
43
  # def title?; end
44
44
  # end
45
45
  # ~~~
46
+ #: [ConstantType = singleton(::ActiveRecord::Base)]
46
47
  class ActionText < Compiler
47
48
  extend T::Sig
48
49
 
49
- ConstantType = type_member { { fixed: T.class_of(::ActiveRecord::Base) } }
50
-
51
- sig { override.void }
50
+ # @override
51
+ #: -> void
52
52
  def decorate
53
53
  root.create_path(constant) do |scope|
54
54
  self.class.action_text_associations(constant).each do |name|
@@ -75,7 +75,7 @@ module Tapioca
75
75
  class << self
76
76
  extend T::Sig
77
77
 
78
- sig { params(constant: T.class_of(::ActiveRecord::Base)).returns(T::Array[String]) }
78
+ #: (singleton(::ActiveRecord::Base) constant) -> Array[String]
79
79
  def action_text_associations(constant)
80
80
  # Implementation copied from https://github.com/rails/rails/blob/31052d0e518b9da103eea2f79d250242ed1e3705/actiontext/lib/action_text/attribute.rb#L66
81
81
  constant.reflect_on_all_associations(:has_one)
@@ -83,7 +83,8 @@ module Tapioca
83
83
  .select { |n| n.start_with?("rich_text_") }
84
84
  end
85
85
 
86
- sig { override.returns(T::Enumerable[Module]) }
86
+ # @override
87
+ #: -> T::Enumerable[Module]
87
88
  def gather_constants
88
89
  descendants_of(::ActiveRecord::Base)
89
90
  .reject(&:abstract_class?)
@@ -38,12 +38,12 @@ module Tapioca
38
38
  # def self.perform_now(user); end
39
39
  # end
40
40
  # ~~~
41
+ #: [ConstantType = singleton(::ActiveJob::Base)]
41
42
  class ActiveJob < Compiler
42
43
  extend T::Sig
43
44
 
44
- ConstantType = type_member { { fixed: T.class_of(::ActiveJob::Base) } }
45
-
46
- sig { override.void }
45
+ # @override
46
+ #: -> void
47
47
  def decorate
48
48
  return unless constant.instance_methods(false).include?(:perform)
49
49
 
@@ -71,12 +71,7 @@ module Tapioca
71
71
 
72
72
  private
73
73
 
74
- sig do
75
- params(
76
- parameters: T::Array[RBI::TypedParam],
77
- constant_name: T.nilable(String),
78
- ).returns(T::Array[RBI::TypedParam])
79
- end
74
+ #: (Array[RBI::TypedParam] parameters, String? constant_name) -> Array[RBI::TypedParam]
80
75
  def perform_later_parameters(parameters, constant_name)
81
76
  if ::Gem::Requirement.new(">= 7.0").satisfied_by?(::ActiveJob.gem_version)
82
77
  parameters.reject! { |typed_param| RBI::BlockParam === typed_param.param }
@@ -92,7 +87,8 @@ module Tapioca
92
87
  class << self
93
88
  extend T::Sig
94
89
 
95
- sig { override.returns(T::Enumerable[Module]) }
90
+ # @override
91
+ #: -> T::Enumerable[Module]
96
92
  def gather_constants
97
93
  descendants_of(::ActiveJob::Base)
98
94
  end
@@ -34,14 +34,12 @@ module Tapioca
34
34
  # def name=(name); end
35
35
  # end
36
36
  # ~~~
37
+ #: [ConstantType = (Class[::ActiveModel::Attributes] & ::ActiveModel::Attributes::ClassMethods)]
37
38
  class ActiveModelAttributes < Compiler
38
39
  extend T::Sig
39
40
 
40
- ConstantType = type_member do
41
- { fixed: T.all(T::Class[::ActiveModel::Attributes], ::ActiveModel::Attributes::ClassMethods) }
42
- end
43
-
44
- sig { override.void }
41
+ # @override
42
+ #: -> void
45
43
  def decorate
46
44
  attribute_methods = attribute_methods_for_constant
47
45
  return if attribute_methods.empty?
@@ -56,7 +54,8 @@ module Tapioca
56
54
  class << self
57
55
  extend T::Sig
58
56
 
59
- sig { override.returns(T::Enumerable[Module]) }
57
+ # @override
58
+ #: -> T::Enumerable[Module]
60
59
  def gather_constants
61
60
  all_classes.grep(::ActiveModel::Attributes::ClassMethods)
62
61
  end
@@ -64,9 +63,9 @@ module Tapioca
64
63
 
65
64
  private
66
65
 
67
- HANDLED_METHOD_TARGETS = T.let(["attribute", "attribute="], T::Array[String])
66
+ HANDLED_METHOD_TARGETS = ["attribute", "attribute="] #: Array[String]
68
67
 
69
- sig { returns(T::Array[[::String, ::String]]) }
68
+ #: -> Array[[::String, ::String]]
70
69
  def attribute_methods_for_constant
71
70
  patterns = if constant.respond_to?(:attribute_method_patterns)
72
71
  # https://github.com/rails/rails/pull/44367
@@ -83,7 +82,7 @@ module Tapioca
83
82
  end
84
83
  end
85
84
 
86
- sig { params(pattern: T.untyped).returns(T::Boolean) }
85
+ #: (untyped pattern) -> bool
87
86
  def handle_method_pattern?(pattern)
88
87
  target = if pattern.respond_to?(:method_missing_target)
89
88
  # Pre-Rails 6.0, the field is named "method_missing_target"
@@ -99,7 +98,7 @@ module Tapioca
99
98
  HANDLED_METHOD_TARGETS.include?(target.to_s)
100
99
  end
101
100
 
102
- sig { params(attribute_type_value: T.untyped).returns(::String) }
101
+ #: (untyped attribute_type_value) -> ::String
103
102
  def type_for(attribute_type_value)
104
103
  case attribute_type_value
105
104
  when ActiveModel::Type::Boolean
@@ -123,7 +122,7 @@ module Tapioca
123
122
  end
124
123
  end
125
124
 
126
- sig { params(klass: RBI::Scope, method: String, type: String).void }
125
+ #: (RBI::Scope klass, String method, String type) -> void
127
126
  def generate_method(klass, method, type)
128
127
  if method.end_with?("=")
129
128
  parameter = create_param("value", type: type)
@@ -53,14 +53,12 @@ module Tapioca
53
53
  # def token_confirmation=(unencrypted_password); end
54
54
  # end
55
55
  # ~~~
56
+ #: [ConstantType = (Class[::ActiveModel::SecurePassword] & ::ActiveModel::SecurePassword::ClassMethods)]
56
57
  class ActiveModelSecurePassword < Compiler
57
58
  extend T::Sig
58
59
 
59
- ConstantType = type_member do
60
- { fixed: T.all(T::Class[::ActiveModel::SecurePassword], ::ActiveModel::SecurePassword::ClassMethods) }
61
- end
62
-
63
- sig { override.void }
60
+ # @override
61
+ #: -> void
64
62
  def decorate
65
63
  instance_methods_modules = if constant < ActiveModel::SecurePassword::InstanceMethodsOnActivation
66
64
  # pre Rails 6.0, this used to be a single static module
@@ -94,7 +92,8 @@ module Tapioca
94
92
  class << self
95
93
  extend T::Sig
96
94
 
97
- sig { override.returns(T::Enumerable[Module]) }
95
+ # @override
96
+ #: -> T::Enumerable[Module]
98
97
  def gather_constants
99
98
  # This selects all classes that are `ActiveModel::SecurePassword::ClassMethods === klass`.
100
99
  # In other words, we select all classes that have `ActiveModel::SecurePassword::ClassMethods`
@@ -40,28 +40,21 @@ module Tapioca
40
40
  # def password_confirmation=(password_confirmation); end
41
41
  # end
42
42
  # ~~~
43
+ #: [ConstantType = (Class[ActiveModel::Validations] & ActiveModel::Validations::HelperMethods & ActiveModel::Validations::ClassMethods)]
43
44
  class ActiveModelValidationsConfirmation < Compiler
44
45
  extend T::Sig
45
46
 
46
- ConstantType = type_member do
47
- {
48
- fixed: T.all(
49
- T::Class[ActiveModel::Validations],
50
- ActiveModel::Validations::HelperMethods,
51
- ActiveModel::Validations::ClassMethods,
52
- ),
53
- }
54
- end
55
-
56
47
  class << self
57
- sig { override.returns(T::Enumerable[Module]) }
48
+ # @override
49
+ #: -> T::Enumerable[Module]
58
50
  def gather_constants
59
51
  # Collect all the classes that include ActiveModel::Validations
60
52
  all_classes.select { |c| ActiveModel::Validations > c }
61
53
  end
62
54
  end
63
55
 
64
- sig { override.void }
56
+ # @override
57
+ #: -> void
65
58
  def decorate
66
59
  confirmation_validators = constant.validators.grep(ActiveModel::Validations::ConfirmationValidator)
67
60
 
@@ -101,6 +101,7 @@ module Tapioca
101
101
  # end
102
102
  # end
103
103
  # ~~~
104
+ #: [ConstantType = singleton(ActiveRecord::Base)]
104
105
  class ActiveRecordAssociations < Compiler
105
106
  extend T::Sig
106
107
  include Helpers::ActiveRecordConstantsHelper
@@ -111,19 +112,18 @@ module Tapioca
111
112
  class MissingConstantError < StandardError
112
113
  extend T::Sig
113
114
 
114
- sig { returns(String) }
115
+ #: String
115
116
  attr_reader :class_name
116
117
 
117
- sig { params(class_name: String).void }
118
+ #: (String class_name) -> void
118
119
  def initialize(class_name)
119
120
  @class_name = class_name
120
121
  super
121
122
  end
122
123
  end
123
124
 
124
- ConstantType = type_member { { fixed: T.class_of(ActiveRecord::Base) } }
125
-
126
- sig { override.void }
125
+ # @override
126
+ #: -> void
127
127
  def decorate
128
128
  return if constant.reflections.empty?
129
129
 
@@ -140,7 +140,8 @@ module Tapioca
140
140
  class << self
141
141
  extend T::Sig
142
142
 
143
- sig { override.returns(T::Enumerable[Module]) }
143
+ # @override
144
+ #: -> T::Enumerable[Module]
144
145
  def gather_constants
145
146
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
146
147
  end
@@ -148,7 +149,7 @@ module Tapioca
148
149
 
149
150
  private
150
151
 
151
- sig { params(mod: RBI::Scope).void }
152
+ #: (RBI::Scope mod) -> void
152
153
  def populate_nested_attribute_writers(mod)
153
154
  constant.nested_attributes_options.keys.each do |association_name|
154
155
  mod.create_method(
@@ -159,7 +160,7 @@ module Tapioca
159
160
  end
160
161
  end
161
162
 
162
- sig { params(mod: RBI::Scope).void }
163
+ #: (RBI::Scope mod) -> void
163
164
  def populate_associations(mod)
164
165
  constant.reflections.each do |association_name, reflection|
165
166
  if reflection.collection?
@@ -178,13 +179,7 @@ module Tapioca
178
179
  end
179
180
  end
180
181
 
181
- sig do
182
- params(
183
- klass: RBI::Scope,
184
- association_name: T.any(String, Symbol),
185
- reflection: ReflectionType,
186
- ).void
187
- end
182
+ #: (RBI::Scope klass, (String | Symbol) association_name, ReflectionType reflection) -> void
188
183
  def populate_single_assoc_getter_setter(klass, association_name, reflection)
189
184
  association_class = type_for(reflection)
190
185
  association_type = as_nilable_type(association_class)
@@ -247,13 +242,7 @@ module Tapioca
247
242
  end
248
243
  end
249
244
 
250
- sig do
251
- params(
252
- klass: RBI::Scope,
253
- association_name: T.any(String, Symbol),
254
- reflection: ReflectionType,
255
- ).void
256
- end
245
+ #: (RBI::Scope klass, (String | Symbol) association_name, ReflectionType reflection) -> void
257
246
  def populate_collection_assoc_getter_setter(klass, association_name, reflection)
258
247
  association_class = type_for(reflection)
259
248
  relation_class = relation_type_for(reflection)
@@ -279,11 +268,7 @@ module Tapioca
279
268
  )
280
269
  end
281
270
 
282
- sig do
283
- params(
284
- reflection: ReflectionType,
285
- ).returns(String)
286
- end
271
+ #: (ReflectionType reflection) -> String
287
272
  def type_for(reflection)
288
273
  validate_reflection!(reflection)
289
274
 
@@ -292,11 +277,7 @@ module Tapioca
292
277
  T.must(qualified_name_of(reflection.klass))
293
278
  end
294
279
 
295
- sig do
296
- params(
297
- reflection: ReflectionType,
298
- ).void
299
- end
280
+ #: (ReflectionType reflection) -> void
300
281
  def validate_reflection!(reflection)
301
282
  # Check existence of source reflection, first, since, calling
302
283
  # `.klass` also tries to go through the source reflection
@@ -320,7 +301,7 @@ module Tapioca
320
301
  raise MissingConstantError, class_name
321
302
  end
322
303
 
323
- sig { params(reflection: ReflectionType).returns(T.nilable(String)) }
304
+ #: (ReflectionType reflection) -> String?
324
305
  def declaration(reflection)
325
306
  case reflection
326
307
  when ActiveRecord::Reflection::HasOneReflection
@@ -340,7 +321,7 @@ module Tapioca
340
321
  end
341
322
  end
342
323
 
343
- sig { params(reflection: ReflectionType).returns(T::Array[RBI::Comment]) }
324
+ #: (ReflectionType reflection) -> Array[RBI::Comment]
344
325
  def association_comments(reflection)
345
326
  anchor_name = case reflection
346
327
  when ActiveRecord::Reflection::HasOneReflection
@@ -374,11 +355,7 @@ module Tapioca
374
355
  end
375
356
  end
376
357
 
377
- sig do
378
- params(
379
- reflection: ReflectionType,
380
- ).returns(String)
381
- end
358
+ #: (ReflectionType reflection) -> String
382
359
  def relation_type_for(reflection)
383
360
  validate_reflection!(reflection)
384
361
 
@@ -398,11 +375,7 @@ module Tapioca
398
375
  end
399
376
  end
400
377
 
401
- sig do
402
- params(
403
- reflection: ReflectionType,
404
- ).returns(T::Boolean)
405
- end
378
+ #: (ReflectionType reflection) -> bool
406
379
  def polymorphic_association?(reflection)
407
380
  if reflection.through_reflection?
408
381
  polymorphic_association?(reflection.source_reflection)
@@ -120,13 +120,13 @@ module Tapioca
120
120
  # sig { returns(T.untyped) }
121
121
  # def title; end
122
122
  # ~~~
123
+ #: [ConstantType = singleton(ActiveRecord::Base)]
123
124
  class ActiveRecordColumns < Compiler
124
125
  extend T::Sig
125
126
  include Helpers::ActiveRecordConstantsHelper
126
127
 
127
- ConstantType = type_member { { fixed: T.class_of(ActiveRecord::Base) } }
128
-
129
- sig { override.void }
128
+ # @override
129
+ #: -> void
130
130
  def decorate
131
131
  return unless constant.table_exists?
132
132
 
@@ -165,7 +165,8 @@ module Tapioca
165
165
  class << self
166
166
  extend T::Sig
167
167
 
168
- sig { override.returns(T::Enumerable[Module]) }
168
+ # @override
169
+ #: -> T::Enumerable[Module]
169
170
  def gather_constants
170
171
  descendants_of(::ActiveRecord::Base).reject(&:abstract_class?)
171
172
  end
@@ -175,7 +176,7 @@ module Tapioca
175
176
 
176
177
  ColumnTypeOption = Helpers::ActiveRecordColumnTypeHelper::ColumnTypeOption
177
178
 
178
- sig { returns(ColumnTypeOption) }
179
+ #: -> ColumnTypeOption
179
180
  def column_type_option
180
181
  @column_type_option ||= T.let(
181
182
  ColumnTypeOption.from_options(options) do |value, default_column_type_option|
@@ -188,15 +189,7 @@ module Tapioca
188
189
  )
189
190
  end
190
191
 
191
- sig do
192
- params(
193
- klass: RBI::Scope,
194
- name: String,
195
- methods_to_add: T.nilable(T::Array[String]),
196
- return_type: String,
197
- parameters: T::Array[RBI::TypedParam],
198
- ).void
199
- end
192
+ #: (RBI::Scope klass, String name, Array[String]? methods_to_add, ?return_type: String, ?parameters: Array[RBI::TypedParam]) -> void
200
193
  def add_method(klass, name, methods_to_add, return_type: "void", parameters: [])
201
194
  klass.create_method(
202
195
  name,
@@ -205,14 +198,7 @@ module Tapioca
205
198
  ) if methods_to_add.nil? || methods_to_add.include?(name)
206
199
  end
207
200
 
208
- sig do
209
- params(
210
- klass: RBI::Scope,
211
- attribute_name: String,
212
- column_name: String,
213
- methods_to_add: T.nilable(T::Array[String]),
214
- ).void
215
- end
201
+ #: (RBI::Scope klass, String attribute_name, ?String column_name, ?Array[String]? methods_to_add) -> void
216
202
  def add_methods_for_attribute(klass, attribute_name, column_name = attribute_name, methods_to_add = nil)
217
203
  getter_type, setter_type = Helpers::ActiveRecordColumnTypeHelper
218
204
  .new(constant, column_type_option: column_type_option)
@@ -277,12 +263,20 @@ module Tapioca
277
263
  "saved_change_to_#{attribute_name}?",
278
264
  methods_to_add,
279
265
  return_type: "T::Boolean",
266
+ parameters: [
267
+ create_kw_opt_param("from", type: "T.untyped", default: "T.unsafe(nil)"),
268
+ create_kw_opt_param("to", type: "T.untyped", default: "T.unsafe(nil)"),
269
+ ],
280
270
  )
281
271
  add_method(
282
272
  klass,
283
273
  "will_save_change_to_#{attribute_name}?",
284
274
  methods_to_add,
285
275
  return_type: "T::Boolean",
276
+ parameters: [
277
+ create_kw_opt_param("from", type: "T.untyped", default: "T.unsafe(nil)"),
278
+ create_kw_opt_param("to", type: "T.untyped", default: "T.unsafe(nil)"),
279
+ ],
286
280
  )
287
281
 
288
282
  # Added by ActiveModel::Dirty
@@ -299,8 +293,8 @@ module Tapioca
299
293
  methods_to_add,
300
294
  return_type: "T::Boolean",
301
295
  parameters: [
302
- create_kw_opt_param("from", type: setter_type, default: "T.unsafe(nil)"),
303
- create_kw_opt_param("to", type: setter_type, default: "T.unsafe(nil)"),
296
+ create_kw_opt_param("from", type: "T.untyped", default: "T.unsafe(nil)"),
297
+ create_kw_opt_param("to", type: "T.untyped", default: "T.unsafe(nil)"),
304
298
  ],
305
299
  )
306
300
  add_method(
@@ -326,8 +320,8 @@ module Tapioca
326
320
  methods_to_add,
327
321
  return_type: "T::Boolean",
328
322
  parameters: [
329
- create_kw_opt_param("from", type: setter_type, default: "T.unsafe(nil)"),
330
- create_kw_opt_param("to", type: setter_type, default: "T.unsafe(nil)"),
323
+ create_kw_opt_param("from", type: "T.untyped", default: "T.unsafe(nil)"),
324
+ create_kw_opt_param("to", type: "T.untyped", default: "T.unsafe(nil)"),
331
325
  ],
332
326
  )
333
327
  add_method(