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.
- checksums.yaml +4 -4
- data/lib/ruby_lsp/tapioca/addon.rb +24 -20
- 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 +36 -62
- 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 +30 -58
- 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 +5 -4
- 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
@@ -17,12 +17,7 @@ module Tapioca
|
|
17
17
|
4. Manually create an RBI shim defining the missing constants
|
18
18
|
DEPRECATION
|
19
19
|
|
20
|
-
|
21
|
-
params(
|
22
|
-
todo_file: String,
|
23
|
-
file_header: T::Boolean,
|
24
|
-
).void
|
25
|
-
end
|
20
|
+
#: (todo_file: String, file_header: bool) -> void
|
26
21
|
def initialize(todo_file:, file_header:)
|
27
22
|
@todo_file = todo_file
|
28
23
|
@file_header = file_header
|
@@ -30,7 +25,7 @@ module Tapioca
|
|
30
25
|
super()
|
31
26
|
end
|
32
27
|
|
33
|
-
|
28
|
+
#: -> void
|
34
29
|
def run_with_deprecation
|
35
30
|
say(DEPRECATION_MESSAGE, :red)
|
36
31
|
say("")
|
@@ -40,7 +35,8 @@ module Tapioca
|
|
40
35
|
|
41
36
|
private
|
42
37
|
|
43
|
-
|
38
|
+
# @override
|
39
|
+
#: -> void
|
44
40
|
def execute
|
45
41
|
say("Finding all unresolved constants, this may take a few seconds... ")
|
46
42
|
|
@@ -64,7 +60,7 @@ module Tapioca
|
|
64
60
|
say("Please review changes and commit them.", [:green, :bold])
|
65
61
|
end
|
66
62
|
|
67
|
-
|
63
|
+
#: (Array[String] constants, command: String) -> RBI::File
|
68
64
|
def rbi(constants, command:)
|
69
65
|
file = RBI::File.new
|
70
66
|
|
@@ -84,7 +80,7 @@ module Tapioca
|
|
84
80
|
file
|
85
81
|
end
|
86
82
|
|
87
|
-
|
83
|
+
#: -> Array[String]
|
88
84
|
def unresolved_constants
|
89
85
|
# Taken from https://github.com/sorbet/sorbet/blob/master/gems/sorbet/lib/todo-rbi.rb
|
90
86
|
sorbet("--print=missing-constants", "--quiet", "--stdout-hup-hack", "--no-error-count")
|
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
|
|