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