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.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/exe/tapioca +6 -1
- data/lib/ruby_lsp/tapioca/addon.rb +73 -43
- data/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb +43 -43
- data/lib/ruby_lsp/tapioca/server_addon.rb +13 -10
- data/lib/tapioca/bundler_ext/auto_require_hook.rb +6 -14
- data/lib/tapioca/cli.rb +16 -8
- data/lib/tapioca/commands/abstract_dsl.rb +39 -66
- data/lib/tapioca/commands/abstract_gem.rb +25 -46
- data/lib/tapioca/commands/annotations.rb +28 -34
- data/lib/tapioca/commands/check_shims.rb +6 -15
- data/lib/tapioca/commands/command.rb +12 -26
- data/lib/tapioca/commands/command_without_tracker.rb +2 -5
- 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 +5 -9
- 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 +36 -63
- data/lib/tapioca/dsl/compilers/aasm.rb +33 -44
- data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +8 -7
- data/lib/tapioca/dsl/compilers/action_mailer.rb +6 -5
- data/lib/tapioca/dsl/compilers/action_text.rb +6 -5
- data/lib/tapioca/dsl/compilers/active_job.rb +6 -10
- data/lib/tapioca/dsl/compilers/active_model_attributes.rb +10 -11
- data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +5 -6
- data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +5 -12
- data/lib/tapioca/dsl/compilers/active_record_associations.rb +17 -44
- data/lib/tapioca/dsl/compilers/active_record_columns.rb +20 -26
- data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +9 -8
- data/lib/tapioca/dsl/compilers/active_record_enum.rb +7 -6
- data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +54 -62
- data/lib/tapioca/dsl/compilers/active_record_relations.rb +148 -209
- data/lib/tapioca/dsl/compilers/active_record_scope.rb +8 -13
- data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +5 -4
- data/lib/tapioca/dsl/compilers/active_record_store.rb +5 -4
- data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +19 -28
- data/lib/tapioca/dsl/compilers/active_resource.rb +19 -21
- data/lib/tapioca/dsl/compilers/active_storage.rb +6 -14
- data/lib/tapioca/dsl/compilers/active_support_concern.rb +9 -8
- data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +8 -7
- data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +5 -4
- data/lib/tapioca/dsl/compilers/config.rb +5 -4
- data/lib/tapioca/dsl/compilers/frozen_record.rb +7 -11
- data/lib/tapioca/dsl/compilers/graphql_input_object.rb +9 -10
- data/lib/tapioca/dsl/compilers/graphql_mutation.rb +6 -10
- data/lib/tapioca/dsl/compilers/identity_cache.rb +11 -39
- data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +9 -18
- data/lib/tapioca/dsl/compilers/kredis.rb +7 -8
- data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +5 -4
- data/lib/tapioca/dsl/compilers/protobuf.rb +13 -26
- data/lib/tapioca/dsl/compilers/rails_generators.rb +9 -11
- data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +23 -13
- data/lib/tapioca/dsl/compilers/smart_properties.rb +32 -38
- data/lib/tapioca/dsl/compilers/state_machines.rb +15 -26
- data/lib/tapioca/dsl/compilers/url_helpers.rb +10 -9
- 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 +24 -34
- data/lib/tapioca/gem/listeners/base.rb +7 -10
- 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 +36 -47
- 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 +15 -8
- data/lib/tapioca/gem/listeners/subconstants.rb +5 -4
- data/lib/tapioca/gem/listeners/yard_doc.rb +30 -23
- data/lib/tapioca/gem/pipeline.rb +107 -91
- data/lib/tapioca/gem_info.rb +1 -1
- data/lib/tapioca/gemfile.rb +64 -73
- data/lib/tapioca/helpers/cli_helper.rb +4 -7
- data/lib/tapioca/helpers/config_helper.rb +17 -29
- data/lib/tapioca/helpers/env_helper.rb +2 -5
- 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 +76 -73
- 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 +7 -10
- data/lib/tapioca/helpers/test/dsl_compiler.rb +20 -33
- data/lib/tapioca/helpers/test/isolation.rb +10 -14
- data/lib/tapioca/helpers/test/template.rb +6 -11
- data/lib/tapioca/internal.rb +18 -8
- data/lib/tapioca/loaders/dsl.rb +11 -19
- data/lib/tapioca/loaders/gem.rb +6 -21
- data/lib/tapioca/loaders/loader.rb +21 -39
- 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 -9
- data/lib/tapioca/runtime/attached_class_of_32.rb +1 -1
- data/lib/tapioca/runtime/attached_class_of_legacy.rb +2 -5
- 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 +81 -60
- data/lib/tapioca/runtime/source_location.rb +44 -0
- data/lib/tapioca/runtime/trackers/autoload.rb +7 -9
- data/lib/tapioca/runtime/trackers/constant_definition.rb +18 -14
- data/lib/tapioca/runtime/trackers/method_definition.rb +65 -0
- data/lib/tapioca/runtime/trackers/mixin.rb +8 -11
- data/lib/tapioca/runtime/trackers/required_ancestor.rb +3 -3
- data/lib/tapioca/runtime/trackers/tracker.rb +3 -6
- data/lib/tapioca/runtime/trackers.rb +5 -8
- data/lib/tapioca/sorbet_ext/generic_name_patch.rb +9 -15
- data/lib/tapioca/sorbet_ext/name_patch.rb +2 -2
- 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 +27 -10
|
@@ -63,14 +63,12 @@ module Tapioca
|
|
|
63
63
|
# end
|
|
64
64
|
# end
|
|
65
65
|
# ~~~
|
|
66
|
+
#: [ConstantType = (Class[::Kredis::Attributes] & ::Kredis::Attributes::ClassMethods & Extensions::Kredis)]
|
|
66
67
|
class Kredis < Compiler
|
|
67
68
|
extend T::Sig
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
sig { override.void }
|
|
70
|
+
# @override
|
|
71
|
+
#: -> void
|
|
74
72
|
def decorate
|
|
75
73
|
return if constant.__tapioca_kredis_types.nil?
|
|
76
74
|
|
|
@@ -89,7 +87,8 @@ module Tapioca
|
|
|
89
87
|
class << self
|
|
90
88
|
extend T::Sig
|
|
91
89
|
|
|
92
|
-
|
|
90
|
+
# @override
|
|
91
|
+
#: -> T::Enumerable[Module]
|
|
93
92
|
def gather_constants
|
|
94
93
|
all_classes
|
|
95
94
|
.grep(::Kredis::Attributes::ClassMethods)
|
|
@@ -99,7 +98,7 @@ module Tapioca
|
|
|
99
98
|
|
|
100
99
|
private
|
|
101
100
|
|
|
102
|
-
|
|
101
|
+
#: (RBI::Scope mod, String method, Hash[Symbol, untyped] data) -> void
|
|
103
102
|
def generate_methods(mod, method, data)
|
|
104
103
|
return_type = data.fetch(:type)
|
|
105
104
|
case return_type
|
|
@@ -114,7 +113,7 @@ module Tapioca
|
|
|
114
113
|
mod.create_method(method, return_type: return_type)
|
|
115
114
|
end
|
|
116
115
|
|
|
117
|
-
|
|
116
|
+
#: (RBI::Scope mod, String klass_name, Array[untyped] values) -> void
|
|
118
117
|
def create_enum_class(mod, klass_name, values)
|
|
119
118
|
klass = mod.create_class(klass_name, superclass_name: "Kredis::Types::Enum")
|
|
120
119
|
values.each do |value|
|
|
@@ -44,12 +44,12 @@ module Tapioca
|
|
|
44
44
|
# end
|
|
45
45
|
# end
|
|
46
46
|
# ~~~
|
|
47
|
+
#: [ConstantType = Module]
|
|
47
48
|
class MixedInClassAttributes < Compiler
|
|
48
49
|
extend T::Sig
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
sig { override.void }
|
|
51
|
+
# @override
|
|
52
|
+
#: -> void
|
|
53
53
|
def decorate
|
|
54
54
|
mixin_compiler = Runtime::DynamicMixinCompiler.new(constant)
|
|
55
55
|
return if mixin_compiler.empty_attributes?
|
|
@@ -62,7 +62,8 @@ module Tapioca
|
|
|
62
62
|
class << self
|
|
63
63
|
extend T::Sig
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
# @override
|
|
66
|
+
#: -> T::Enumerable[Module]
|
|
66
67
|
def gather_constants
|
|
67
68
|
# Select all non-anonymous modules that have overridden Module.included
|
|
68
69
|
all_modules.select do |mod|
|
|
@@ -64,6 +64,7 @@ module Tapioca
|
|
|
64
64
|
# ~~~
|
|
65
65
|
# --ignore=/path/to/proto/cart_pb.rb
|
|
66
66
|
# ~~~
|
|
67
|
+
#: [ConstantType = Class[top]]
|
|
67
68
|
class Protobuf < Compiler
|
|
68
69
|
class Field < T::Struct
|
|
69
70
|
prop :name, String
|
|
@@ -74,11 +75,10 @@ module Tapioca
|
|
|
74
75
|
|
|
75
76
|
extend T::Sig
|
|
76
77
|
|
|
77
|
-
ConstantType = type_member { { fixed: T::Class[T.anything] } }
|
|
78
|
-
|
|
79
78
|
FIELD_RE = /^[a-z_][a-zA-Z0-9_]*$/
|
|
80
79
|
|
|
81
|
-
|
|
80
|
+
# @override
|
|
81
|
+
#: -> void
|
|
82
82
|
def decorate
|
|
83
83
|
root.create_path(constant) do |klass|
|
|
84
84
|
if constant == Google::Protobuf::RepeatedField
|
|
@@ -155,7 +155,8 @@ module Tapioca
|
|
|
155
155
|
class << self
|
|
156
156
|
extend T::Sig
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
# @override
|
|
159
|
+
#: -> T::Enumerable[Module]
|
|
159
160
|
def gather_constants
|
|
160
161
|
marker = Google::Protobuf::MessageExts::ClassMethods
|
|
161
162
|
|
|
@@ -178,7 +179,7 @@ module Tapioca
|
|
|
178
179
|
|
|
179
180
|
private
|
|
180
181
|
|
|
181
|
-
|
|
182
|
+
#: (Google::Protobuf::FieldDescriptor desc) -> bool
|
|
182
183
|
def has_presence?(desc)
|
|
183
184
|
if desc.respond_to?(:has_presence?)
|
|
184
185
|
# This method is only defined in google-protobuf 3.26.0 and later
|
|
@@ -190,7 +191,7 @@ module Tapioca
|
|
|
190
191
|
end
|
|
191
192
|
end
|
|
192
193
|
|
|
193
|
-
|
|
194
|
+
#: (RBI::Scope klass, *String names) -> void
|
|
194
195
|
def create_type_members(klass, *names)
|
|
195
196
|
klass.create_extend("T::Generic")
|
|
196
197
|
|
|
@@ -199,11 +200,7 @@ module Tapioca
|
|
|
199
200
|
end
|
|
200
201
|
end
|
|
201
202
|
|
|
202
|
-
|
|
203
|
-
params(
|
|
204
|
-
descriptor: Google::Protobuf::FieldDescriptor,
|
|
205
|
-
).returns(String)
|
|
206
|
-
end
|
|
203
|
+
#: (Google::Protobuf::FieldDescriptor descriptor) -> String
|
|
207
204
|
def type_of(descriptor)
|
|
208
205
|
case descriptor.type
|
|
209
206
|
when :enum
|
|
@@ -229,12 +226,12 @@ module Tapioca
|
|
|
229
226
|
end
|
|
230
227
|
end
|
|
231
228
|
|
|
232
|
-
|
|
229
|
+
#: (Google::Protobuf::FieldDescriptor descriptor) -> bool
|
|
233
230
|
def nilable_descriptor?(descriptor)
|
|
234
231
|
descriptor.label == :optional && descriptor.type == :message
|
|
235
232
|
end
|
|
236
233
|
|
|
237
|
-
|
|
234
|
+
#: (Google::Protobuf::FieldDescriptor descriptor) -> bool
|
|
238
235
|
def map_type?(descriptor)
|
|
239
236
|
# Defensively make sure that we are dealing with a repeated field
|
|
240
237
|
return false unless descriptor.label == :repeated
|
|
@@ -248,7 +245,7 @@ module Tapioca
|
|
|
248
245
|
false
|
|
249
246
|
end
|
|
250
247
|
|
|
251
|
-
|
|
248
|
+
#: (Google::Protobuf::FieldDescriptor descriptor) -> Field
|
|
252
249
|
def field_of(descriptor)
|
|
253
250
|
if descriptor.label == :repeated
|
|
254
251
|
if map_type?(descriptor)
|
|
@@ -290,12 +287,7 @@ module Tapioca
|
|
|
290
287
|
end
|
|
291
288
|
end
|
|
292
289
|
|
|
293
|
-
|
|
294
|
-
params(
|
|
295
|
-
klass: RBI::Scope,
|
|
296
|
-
desc: Google::Protobuf::FieldDescriptor,
|
|
297
|
-
).returns(Field)
|
|
298
|
-
end
|
|
290
|
+
#: (RBI::Scope klass, Google::Protobuf::FieldDescriptor desc) -> Field
|
|
299
291
|
def create_descriptor_method(klass, desc)
|
|
300
292
|
field = field_of(desc)
|
|
301
293
|
|
|
@@ -325,12 +317,7 @@ module Tapioca
|
|
|
325
317
|
field
|
|
326
318
|
end
|
|
327
319
|
|
|
328
|
-
|
|
329
|
-
params(
|
|
330
|
-
klass: RBI::Scope,
|
|
331
|
-
desc: Google::Protobuf::OneofDescriptor,
|
|
332
|
-
).void
|
|
333
|
-
end
|
|
320
|
+
#: (RBI::Scope klass, Google::Protobuf::OneofDescriptor desc) -> void
|
|
334
321
|
def create_oneof_method(klass, desc)
|
|
335
322
|
klass.create_method(
|
|
336
323
|
desc.name,
|
|
@@ -33,17 +33,14 @@ module Tapioca
|
|
|
33
33
|
# def skip_comments; end
|
|
34
34
|
# end
|
|
35
35
|
# ~~~
|
|
36
|
+
#: [ConstantType = singleton(::Rails::Generators::Base)]
|
|
36
37
|
class RailsGenerators < Compiler
|
|
37
38
|
extend T::Sig
|
|
38
39
|
|
|
39
|
-
BUILT_IN_MATCHER =
|
|
40
|
-
/::(ActionMailbox|ActionText|ActiveRecord|Rails)::Generators/,
|
|
41
|
-
Regexp,
|
|
42
|
-
)
|
|
40
|
+
BUILT_IN_MATCHER = /::(ActionMailbox|ActionText|ActiveRecord|Rails)::Generators/
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
sig { override.void }
|
|
42
|
+
# @override
|
|
43
|
+
#: -> void
|
|
47
44
|
def decorate
|
|
48
45
|
base_class = base_class_of_constant
|
|
49
46
|
arguments = constant.arguments - base_class.arguments
|
|
@@ -62,7 +59,8 @@ module Tapioca
|
|
|
62
59
|
class << self
|
|
63
60
|
extend T::Sig
|
|
64
61
|
|
|
65
|
-
|
|
62
|
+
# @override
|
|
63
|
+
#: -> T::Enumerable[Module]
|
|
66
64
|
def gather_constants
|
|
67
65
|
all_classes.select do |const|
|
|
68
66
|
name = qualified_name_of(const)
|
|
@@ -76,7 +74,7 @@ module Tapioca
|
|
|
76
74
|
|
|
77
75
|
private
|
|
78
76
|
|
|
79
|
-
|
|
77
|
+
#: (RBI::Tree klass, (Thor::Argument | Thor::Option) argument) -> void
|
|
80
78
|
def generate_methods_for_argument(klass, argument)
|
|
81
79
|
klass.create_method(
|
|
82
80
|
argument.name,
|
|
@@ -85,7 +83,7 @@ module Tapioca
|
|
|
85
83
|
)
|
|
86
84
|
end
|
|
87
85
|
|
|
88
|
-
|
|
86
|
+
#: -> singleton(::Rails::Generators::Base)
|
|
89
87
|
def base_class_of_constant
|
|
90
88
|
ancestor = inherited_ancestors_of(constant).find do |klass|
|
|
91
89
|
qualified_name_of(klass)&.match?(BUILT_IN_MATCHER)
|
|
@@ -94,7 +92,7 @@ module Tapioca
|
|
|
94
92
|
T.cast(ancestor, T.class_of(::Rails::Generators::Base))
|
|
95
93
|
end
|
|
96
94
|
|
|
97
|
-
|
|
95
|
+
#: ((Thor::Argument | Thor::Option) arg) -> String
|
|
98
96
|
def type_for(arg)
|
|
99
97
|
type =
|
|
100
98
|
case arg.type
|
|
@@ -36,12 +36,17 @@ module Tapioca
|
|
|
36
36
|
# def self.perform_in(interval, customer_id); end
|
|
37
37
|
# end
|
|
38
38
|
# ~~~
|
|
39
|
+
#
|
|
40
|
+
# If your project uses `ActiveSupport` as well, then the compiler will automatically add its classes
|
|
41
|
+
# as accepted values for the `interval` parameter:
|
|
42
|
+
# * `self.perform_at` will also accept a `ActiveSupport::TimeWithZone` value
|
|
43
|
+
# * `self.perform_in` will also accept a `ActiveSupport::Duration` value
|
|
44
|
+
#: [ConstantType = singleton(::Sidekiq::Worker)]
|
|
39
45
|
class SidekiqWorker < Compiler
|
|
40
46
|
extend T::Sig
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
sig { override.void }
|
|
48
|
+
# @override
|
|
49
|
+
#: -> void
|
|
45
50
|
def decorate
|
|
46
51
|
return unless constant.instance_methods.include?(:perform)
|
|
47
52
|
|
|
@@ -53,12 +58,22 @@ module Tapioca
|
|
|
53
58
|
# `perform_at` and is just an alias for `perform_in` so both methods technically
|
|
54
59
|
# accept a datetime, time, or numeric but we're typing them differently so they
|
|
55
60
|
# semantically make sense.
|
|
61
|
+
at_return_type = if defined?(ActiveSupport::TimeWithZone)
|
|
62
|
+
"T.any(DateTime, Time, ActiveSupport::TimeWithZone)"
|
|
63
|
+
else
|
|
64
|
+
"T.any(DateTime, Time)"
|
|
65
|
+
end
|
|
56
66
|
at_params = [
|
|
57
|
-
create_param("interval", type:
|
|
67
|
+
create_param("interval", type: at_return_type),
|
|
58
68
|
*async_params,
|
|
59
69
|
]
|
|
70
|
+
in_return_type = if defined?(ActiveSupport::Duration)
|
|
71
|
+
"T.any(Numeric, ActiveSupport::Duration)"
|
|
72
|
+
else
|
|
73
|
+
"Numeric"
|
|
74
|
+
end
|
|
60
75
|
in_params = [
|
|
61
|
-
create_param("interval", type:
|
|
76
|
+
create_param("interval", type: in_return_type),
|
|
62
77
|
*async_params,
|
|
63
78
|
]
|
|
64
79
|
|
|
@@ -71,7 +86,8 @@ module Tapioca
|
|
|
71
86
|
class << self
|
|
72
87
|
extend T::Sig
|
|
73
88
|
|
|
74
|
-
|
|
89
|
+
# @override
|
|
90
|
+
#: -> T::Enumerable[Module]
|
|
75
91
|
def gather_constants
|
|
76
92
|
all_classes.select { |c| Sidekiq::Worker > c }
|
|
77
93
|
end
|
|
@@ -79,13 +95,7 @@ module Tapioca
|
|
|
79
95
|
|
|
80
96
|
private
|
|
81
97
|
|
|
82
|
-
|
|
83
|
-
params(
|
|
84
|
-
worker: RBI::Scope,
|
|
85
|
-
method_name: String,
|
|
86
|
-
parameters: T::Array[RBI::TypedParam],
|
|
87
|
-
).void
|
|
88
|
-
end
|
|
98
|
+
#: (RBI::Scope worker, String method_name, Array[RBI::TypedParam] parameters) -> void
|
|
89
99
|
def generate_perform_method(worker, method_name, parameters)
|
|
90
100
|
if constant.method(method_name.to_sym).owner == Sidekiq::Worker::ClassMethods
|
|
91
101
|
worker.create_method(method_name, parameters: parameters, return_type: "String", class_method: true)
|
|
@@ -29,42 +29,43 @@ module Tapioca
|
|
|
29
29
|
# # post.rbi
|
|
30
30
|
# # typed: true
|
|
31
31
|
# class Post
|
|
32
|
-
#
|
|
33
|
-
# def title; end
|
|
32
|
+
# include SmartPropertiesGeneratedMethods
|
|
34
33
|
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
34
|
+
# module SmartPropertiesGeneratedMethods
|
|
35
|
+
# sig { returns(T.nilable(::String)) }
|
|
36
|
+
# def title; end
|
|
37
37
|
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
38
|
+
# sig { params(title: T.nilable(::String)).returns(T.nilable(::String)) }
|
|
39
|
+
# def title=(title); end
|
|
40
40
|
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
41
|
+
# sig { returns(::String) }
|
|
42
|
+
# def description; end
|
|
43
43
|
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
44
|
+
# sig { params(description: ::String).returns(::String) }
|
|
45
|
+
# def description=(description); end
|
|
46
46
|
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
47
|
+
# sig { returns(T.nilable(T::Boolean)) }
|
|
48
|
+
# def published?; end
|
|
49
49
|
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
50
|
+
# sig { params(published: T.nilable(T::Boolean)).returns(T.nilable(T::Boolean)) }
|
|
51
|
+
# def published=(published); end
|
|
52
52
|
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
53
|
+
# sig { returns(T.nilable(T::Boolean)) }
|
|
54
|
+
# def enabled; end
|
|
55
|
+
#
|
|
56
|
+
# sig { params(enabled: T.nilable(T::Boolean)).returns(T.nilable(T::Boolean)) }
|
|
57
|
+
# def enabled=(enabled); end
|
|
58
|
+
# end
|
|
55
59
|
# end
|
|
56
60
|
# ~~~
|
|
61
|
+
#: [ConstantType = singleton(::SmartProperties)]
|
|
57
62
|
class SmartProperties < Compiler
|
|
58
63
|
extend T::Sig
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
sig { override.void }
|
|
65
|
+
# @override
|
|
66
|
+
#: -> void
|
|
63
67
|
def decorate
|
|
64
|
-
properties = T.
|
|
65
|
-
T.unsafe(constant).properties,
|
|
66
|
-
::SmartProperties::PropertyCollection,
|
|
67
|
-
)
|
|
68
|
+
properties = T.unsafe(constant).properties #: ::SmartProperties::PropertyCollection
|
|
68
69
|
return if properties.keys.empty?
|
|
69
70
|
|
|
70
71
|
root.create_path(constant) do |k|
|
|
@@ -82,7 +83,8 @@ module Tapioca
|
|
|
82
83
|
class << self
|
|
83
84
|
extend T::Sig
|
|
84
85
|
|
|
85
|
-
|
|
86
|
+
# @override
|
|
87
|
+
#: -> T::Enumerable[Module]
|
|
86
88
|
def gather_constants
|
|
87
89
|
all_modules.select do |c|
|
|
88
90
|
name_of(c) &&
|
|
@@ -95,12 +97,7 @@ module Tapioca
|
|
|
95
97
|
|
|
96
98
|
private
|
|
97
99
|
|
|
98
|
-
|
|
99
|
-
params(
|
|
100
|
-
mod: RBI::Scope,
|
|
101
|
-
property: ::SmartProperties::Property,
|
|
102
|
-
).void
|
|
103
|
-
end
|
|
100
|
+
#: (RBI::Scope mod, ::SmartProperties::Property property) -> void
|
|
104
101
|
def generate_methods_for_property(mod, property)
|
|
105
102
|
type = type_for(property)
|
|
106
103
|
|
|
@@ -114,15 +111,12 @@ module Tapioca
|
|
|
114
111
|
mod.create_method(property.reader.to_s, return_type: type)
|
|
115
112
|
end
|
|
116
113
|
|
|
117
|
-
BOOLEANS =
|
|
118
|
-
[
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
].freeze,
|
|
122
|
-
T::Array[[T::Boolean, T::Boolean]],
|
|
123
|
-
)
|
|
114
|
+
BOOLEANS = [
|
|
115
|
+
[true, false],
|
|
116
|
+
[false, true],
|
|
117
|
+
].freeze #: Array[[bool, bool]]
|
|
124
118
|
|
|
125
|
-
|
|
119
|
+
#: (::SmartProperties::Property property) -> String
|
|
126
120
|
def type_for(property)
|
|
127
121
|
converter, accepter, required = property.to_h.fetch_values(
|
|
128
122
|
:converter,
|
|
@@ -109,12 +109,12 @@ module Tapioca
|
|
|
109
109
|
# end
|
|
110
110
|
# end
|
|
111
111
|
# ~~~
|
|
112
|
+
#: [ConstantType = (Module & ::StateMachines::ClassMethods)]
|
|
112
113
|
class StateMachines < Compiler
|
|
113
114
|
extend T::Sig
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
sig { override.void }
|
|
116
|
+
# @override
|
|
117
|
+
#: -> void
|
|
118
118
|
def decorate
|
|
119
119
|
return if constant.state_machines.empty?
|
|
120
120
|
|
|
@@ -157,7 +157,8 @@ module Tapioca
|
|
|
157
157
|
class << self
|
|
158
158
|
extend T::Sig
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
# @override
|
|
161
|
+
#: -> T::Enumerable[Module]
|
|
161
162
|
def gather_constants
|
|
162
163
|
all_classes.select { |mod| ::StateMachines::InstanceMethods > mod }
|
|
163
164
|
end
|
|
@@ -165,7 +166,7 @@ module Tapioca
|
|
|
165
166
|
|
|
166
167
|
private
|
|
167
168
|
|
|
168
|
-
|
|
169
|
+
#: (::StateMachines::Machine machine) -> String
|
|
169
170
|
def state_type_for(machine)
|
|
170
171
|
value_types = machine.states.map { |state| state.value.class.name }.uniq
|
|
171
172
|
|
|
@@ -176,7 +177,7 @@ module Tapioca
|
|
|
176
177
|
end
|
|
177
178
|
end
|
|
178
179
|
|
|
179
|
-
|
|
180
|
+
#: (RBI::Module instance_module) -> void
|
|
180
181
|
def define_activerecord_methods(instance_module)
|
|
181
182
|
instance_module.create_method(
|
|
182
183
|
"changed_for_autosave?",
|
|
@@ -184,7 +185,7 @@ module Tapioca
|
|
|
184
185
|
)
|
|
185
186
|
end
|
|
186
187
|
|
|
187
|
-
|
|
188
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine) -> void
|
|
188
189
|
def define_state_methods(instance_module, machine)
|
|
189
190
|
machine.states.each do |state|
|
|
190
191
|
instance_module.create_method(
|
|
@@ -194,7 +195,7 @@ module Tapioca
|
|
|
194
195
|
end
|
|
195
196
|
end
|
|
196
197
|
|
|
197
|
-
|
|
198
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine) -> void
|
|
198
199
|
def define_event_methods(instance_module, machine)
|
|
199
200
|
machine.events.each do |event|
|
|
200
201
|
instance_module.create_method(
|
|
@@ -219,13 +220,7 @@ module Tapioca
|
|
|
219
220
|
end
|
|
220
221
|
end
|
|
221
222
|
|
|
222
|
-
|
|
223
|
-
params(
|
|
224
|
-
instance_module: RBI::Module,
|
|
225
|
-
machine: ::StateMachines::Machine,
|
|
226
|
-
state_type: String,
|
|
227
|
-
).void
|
|
228
|
-
end
|
|
223
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine, String state_type) -> void
|
|
229
224
|
def define_state_accessor(instance_module, machine, state_type)
|
|
230
225
|
attribute = machine.attribute.to_s
|
|
231
226
|
instance_module.create_method(
|
|
@@ -239,7 +234,7 @@ module Tapioca
|
|
|
239
234
|
) if ::StateMachines::HelperModule === machine.owner_class.instance_method("#{attribute}=").owner
|
|
240
235
|
end
|
|
241
236
|
|
|
242
|
-
|
|
237
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine) -> void
|
|
243
238
|
def define_state_predicate(instance_module, machine)
|
|
244
239
|
instance_module.create_method(
|
|
245
240
|
"#{machine.name}?",
|
|
@@ -248,7 +243,7 @@ module Tapioca
|
|
|
248
243
|
)
|
|
249
244
|
end
|
|
250
245
|
|
|
251
|
-
|
|
246
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine) -> void
|
|
252
247
|
def define_event_helpers(instance_module, machine)
|
|
253
248
|
events_attribute = machine.attribute(:events).to_s
|
|
254
249
|
transitions_attribute = machine.attribute(:transitions).to_s
|
|
@@ -295,7 +290,7 @@ module Tapioca
|
|
|
295
290
|
end
|
|
296
291
|
end
|
|
297
292
|
|
|
298
|
-
|
|
293
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine) -> void
|
|
299
294
|
def define_path_helpers(instance_module, machine)
|
|
300
295
|
paths_attribute = machine.attribute(:paths).to_s
|
|
301
296
|
|
|
@@ -306,13 +301,7 @@ module Tapioca
|
|
|
306
301
|
)
|
|
307
302
|
end
|
|
308
303
|
|
|
309
|
-
|
|
310
|
-
params(
|
|
311
|
-
instance_module: RBI::Module,
|
|
312
|
-
class_module: RBI::Module,
|
|
313
|
-
machine: ::StateMachines::Machine,
|
|
314
|
-
).void
|
|
315
|
-
end
|
|
304
|
+
#: (RBI::Module instance_module, RBI::Module class_module, ::StateMachines::Machine machine) -> void
|
|
316
305
|
def define_name_helpers(instance_module, class_module, machine)
|
|
317
306
|
name_attribute = machine.attribute(:name).to_s
|
|
318
307
|
event_name_attribute = machine.attribute(:event_name).to_s
|
|
@@ -337,7 +326,7 @@ module Tapioca
|
|
|
337
326
|
)
|
|
338
327
|
end
|
|
339
328
|
|
|
340
|
-
|
|
329
|
+
#: (RBI::Module class_module, ::StateMachines::Machine machine) -> void
|
|
341
330
|
def define_scopes(class_module, machine)
|
|
342
331
|
helper_modules = machine.instance_variable_get(:@helper_modules)
|
|
343
332
|
class_methods = helper_modules[:class].instance_methods(false)
|
|
@@ -78,12 +78,12 @@ module Tapioca
|
|
|
78
78
|
# include GeneratedUrlHelpersModule
|
|
79
79
|
# end
|
|
80
80
|
# ~~~
|
|
81
|
+
#: [ConstantType = Module]
|
|
81
82
|
class UrlHelpers < Compiler
|
|
82
83
|
extend T::Sig
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
sig { override.void }
|
|
85
|
+
# @override
|
|
86
|
+
#: -> void
|
|
87
87
|
def decorate
|
|
88
88
|
case constant
|
|
89
89
|
when GeneratedPathHelpersModule.singleton_class, GeneratedUrlHelpersModule.singleton_class
|
|
@@ -98,7 +98,8 @@ module Tapioca
|
|
|
98
98
|
|
|
99
99
|
class << self
|
|
100
100
|
extend T::Sig
|
|
101
|
-
|
|
101
|
+
# @override
|
|
102
|
+
#: -> T::Enumerable[Module]
|
|
102
103
|
def gather_constants
|
|
103
104
|
return [] unless defined?(Rails.application) && Rails.application
|
|
104
105
|
|
|
@@ -130,7 +131,7 @@ module Tapioca
|
|
|
130
131
|
constants.concat(NON_DISCOVERABLE_INCLUDERS).push(GeneratedUrlHelpersModule, GeneratedPathHelpersModule)
|
|
131
132
|
end
|
|
132
133
|
|
|
133
|
-
|
|
134
|
+
#: -> Array[Module]
|
|
134
135
|
def gather_non_discoverable_includers
|
|
135
136
|
[].tap do |includers|
|
|
136
137
|
if defined?(ActionController::TemplateAssertions) && defined?(ActionDispatch::IntegrationTest)
|
|
@@ -145,7 +146,7 @@ module Tapioca
|
|
|
145
146
|
|
|
146
147
|
# Returns `true` if `mod` "directly" includes `helper`.
|
|
147
148
|
# For classes, this method will return false if the `helper` is included only by a superclass
|
|
148
|
-
|
|
149
|
+
#: (Module mod, Module helper) -> bool
|
|
149
150
|
private def includes_helper?(mod, helper)
|
|
150
151
|
ancestors = ancestors_of(mod)
|
|
151
152
|
|
|
@@ -160,11 +161,11 @@ module Tapioca
|
|
|
160
161
|
end
|
|
161
162
|
end
|
|
162
163
|
|
|
163
|
-
NON_DISCOVERABLE_INCLUDERS =
|
|
164
|
+
NON_DISCOVERABLE_INCLUDERS = gather_non_discoverable_includers #: Array[Module]
|
|
164
165
|
|
|
165
166
|
private
|
|
166
167
|
|
|
167
|
-
|
|
168
|
+
#: (RBI::Tree root, Module constant) -> void
|
|
168
169
|
def generate_module_for(root, constant)
|
|
169
170
|
root.create_module(T.must(constant.name)) do |mod|
|
|
170
171
|
mod.create_include("::ActionDispatch::Routing::UrlFor")
|
|
@@ -180,7 +181,7 @@ module Tapioca
|
|
|
180
181
|
end
|
|
181
182
|
end
|
|
182
183
|
|
|
183
|
-
|
|
184
|
+
#: (RBI::Scope mod, Module helper_module) -> void
|
|
184
185
|
def create_mixins_for(mod, helper_module)
|
|
185
186
|
include_helper = constant.ancestors.include?(helper_module) || NON_DISCOVERABLE_INCLUDERS.include?(constant)
|
|
186
187
|
extend_helper = constant.singleton_class.ancestors.include?(helper_module)
|
|
@@ -10,13 +10,10 @@ module Tapioca
|
|
|
10
10
|
# a different namespace and can only be referred to using their fully
|
|
11
11
|
# qualified name. This constant encapsulates that dual lookup when
|
|
12
12
|
# a compiler needs to be resolved by name.
|
|
13
|
-
NAMESPACES =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
],
|
|
18
|
-
T::Array[String],
|
|
19
|
-
)
|
|
13
|
+
NAMESPACES = [
|
|
14
|
+
"#{name}::", # compilers in this namespace
|
|
15
|
+
"::", # compilers that need to be fully namespaced
|
|
16
|
+
] #: Array[String]
|
|
20
17
|
end
|
|
21
18
|
end
|
|
22
19
|
end
|