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
@@ -59,12 +59,10 @@ module Tapioca
|
|
59
59
|
|
60
60
|
ConstantType = type_member { { fixed: T.class_of(::SmartProperties) } }
|
61
61
|
|
62
|
-
|
62
|
+
# @override
|
63
|
+
#: -> void
|
63
64
|
def decorate
|
64
|
-
properties = T.
|
65
|
-
T.unsafe(constant).properties,
|
66
|
-
::SmartProperties::PropertyCollection,
|
67
|
-
)
|
65
|
+
properties = T.unsafe(constant).properties #: ::SmartProperties::PropertyCollection
|
68
66
|
return if properties.keys.empty?
|
69
67
|
|
70
68
|
root.create_path(constant) do |k|
|
@@ -82,7 +80,8 @@ module Tapioca
|
|
82
80
|
class << self
|
83
81
|
extend T::Sig
|
84
82
|
|
85
|
-
|
83
|
+
# @override
|
84
|
+
#: -> T::Enumerable[Module]
|
86
85
|
def gather_constants
|
87
86
|
all_modules.select do |c|
|
88
87
|
name_of(c) &&
|
@@ -95,12 +94,7 @@ module Tapioca
|
|
95
94
|
|
96
95
|
private
|
97
96
|
|
98
|
-
|
99
|
-
params(
|
100
|
-
mod: RBI::Scope,
|
101
|
-
property: ::SmartProperties::Property,
|
102
|
-
).void
|
103
|
-
end
|
97
|
+
#: (RBI::Scope mod, ::SmartProperties::Property property) -> void
|
104
98
|
def generate_methods_for_property(mod, property)
|
105
99
|
type = type_for(property)
|
106
100
|
|
@@ -114,15 +108,12 @@ module Tapioca
|
|
114
108
|
mod.create_method(property.reader.to_s, return_type: type)
|
115
109
|
end
|
116
110
|
|
117
|
-
BOOLEANS =
|
118
|
-
[
|
119
|
-
|
120
|
-
|
121
|
-
].freeze,
|
122
|
-
T::Array[[T::Boolean, T::Boolean]],
|
123
|
-
)
|
111
|
+
BOOLEANS = [
|
112
|
+
[true, false],
|
113
|
+
[false, true],
|
114
|
+
].freeze #: Array[[bool, bool]]
|
124
115
|
|
125
|
-
|
116
|
+
#: (::SmartProperties::Property property) -> String
|
126
117
|
def type_for(property)
|
127
118
|
converter, accepter, required = property.to_h.fetch_values(
|
128
119
|
:converter,
|
@@ -114,7 +114,8 @@ module Tapioca
|
|
114
114
|
|
115
115
|
ConstantType = type_member { { fixed: T.all(Module, ::StateMachines::ClassMethods) } }
|
116
116
|
|
117
|
-
|
117
|
+
# @override
|
118
|
+
#: -> void
|
118
119
|
def decorate
|
119
120
|
return if constant.state_machines.empty?
|
120
121
|
|
@@ -157,7 +158,8 @@ module Tapioca
|
|
157
158
|
class << self
|
158
159
|
extend T::Sig
|
159
160
|
|
160
|
-
|
161
|
+
# @override
|
162
|
+
#: -> T::Enumerable[Module]
|
161
163
|
def gather_constants
|
162
164
|
all_classes.select { |mod| ::StateMachines::InstanceMethods > mod }
|
163
165
|
end
|
@@ -165,7 +167,7 @@ module Tapioca
|
|
165
167
|
|
166
168
|
private
|
167
169
|
|
168
|
-
|
170
|
+
#: (::StateMachines::Machine machine) -> String
|
169
171
|
def state_type_for(machine)
|
170
172
|
value_types = machine.states.map { |state| state.value.class.name }.uniq
|
171
173
|
|
@@ -176,7 +178,7 @@ module Tapioca
|
|
176
178
|
end
|
177
179
|
end
|
178
180
|
|
179
|
-
|
181
|
+
#: (RBI::Module instance_module) -> void
|
180
182
|
def define_activerecord_methods(instance_module)
|
181
183
|
instance_module.create_method(
|
182
184
|
"changed_for_autosave?",
|
@@ -184,7 +186,7 @@ module Tapioca
|
|
184
186
|
)
|
185
187
|
end
|
186
188
|
|
187
|
-
|
189
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine) -> void
|
188
190
|
def define_state_methods(instance_module, machine)
|
189
191
|
machine.states.each do |state|
|
190
192
|
instance_module.create_method(
|
@@ -194,7 +196,7 @@ module Tapioca
|
|
194
196
|
end
|
195
197
|
end
|
196
198
|
|
197
|
-
|
199
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine) -> void
|
198
200
|
def define_event_methods(instance_module, machine)
|
199
201
|
machine.events.each do |event|
|
200
202
|
instance_module.create_method(
|
@@ -219,13 +221,7 @@ module Tapioca
|
|
219
221
|
end
|
220
222
|
end
|
221
223
|
|
222
|
-
|
223
|
-
params(
|
224
|
-
instance_module: RBI::Module,
|
225
|
-
machine: ::StateMachines::Machine,
|
226
|
-
state_type: String,
|
227
|
-
).void
|
228
|
-
end
|
224
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine, String state_type) -> void
|
229
225
|
def define_state_accessor(instance_module, machine, state_type)
|
230
226
|
attribute = machine.attribute.to_s
|
231
227
|
instance_module.create_method(
|
@@ -239,7 +235,7 @@ module Tapioca
|
|
239
235
|
) if ::StateMachines::HelperModule === machine.owner_class.instance_method("#{attribute}=").owner
|
240
236
|
end
|
241
237
|
|
242
|
-
|
238
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine) -> void
|
243
239
|
def define_state_predicate(instance_module, machine)
|
244
240
|
instance_module.create_method(
|
245
241
|
"#{machine.name}?",
|
@@ -248,7 +244,7 @@ module Tapioca
|
|
248
244
|
)
|
249
245
|
end
|
250
246
|
|
251
|
-
|
247
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine) -> void
|
252
248
|
def define_event_helpers(instance_module, machine)
|
253
249
|
events_attribute = machine.attribute(:events).to_s
|
254
250
|
transitions_attribute = machine.attribute(:transitions).to_s
|
@@ -295,7 +291,7 @@ module Tapioca
|
|
295
291
|
end
|
296
292
|
end
|
297
293
|
|
298
|
-
|
294
|
+
#: (RBI::Module instance_module, ::StateMachines::Machine machine) -> void
|
299
295
|
def define_path_helpers(instance_module, machine)
|
300
296
|
paths_attribute = machine.attribute(:paths).to_s
|
301
297
|
|
@@ -306,13 +302,7 @@ module Tapioca
|
|
306
302
|
)
|
307
303
|
end
|
308
304
|
|
309
|
-
|
310
|
-
params(
|
311
|
-
instance_module: RBI::Module,
|
312
|
-
class_module: RBI::Module,
|
313
|
-
machine: ::StateMachines::Machine,
|
314
|
-
).void
|
315
|
-
end
|
305
|
+
#: (RBI::Module instance_module, RBI::Module class_module, ::StateMachines::Machine machine) -> void
|
316
306
|
def define_name_helpers(instance_module, class_module, machine)
|
317
307
|
name_attribute = machine.attribute(:name).to_s
|
318
308
|
event_name_attribute = machine.attribute(:event_name).to_s
|
@@ -337,7 +327,7 @@ module Tapioca
|
|
337
327
|
)
|
338
328
|
end
|
339
329
|
|
340
|
-
|
330
|
+
#: (RBI::Module class_module, ::StateMachines::Machine machine) -> void
|
341
331
|
def define_scopes(class_module, machine)
|
342
332
|
helper_modules = machine.instance_variable_get(:@helper_modules)
|
343
333
|
class_methods = helper_modules[:class].instance_methods(false)
|
@@ -83,7 +83,8 @@ module Tapioca
|
|
83
83
|
|
84
84
|
ConstantType = type_member { { fixed: Module } }
|
85
85
|
|
86
|
-
|
86
|
+
# @override
|
87
|
+
#: -> void
|
87
88
|
def decorate
|
88
89
|
case constant
|
89
90
|
when GeneratedPathHelpersModule.singleton_class, GeneratedUrlHelpersModule.singleton_class
|
@@ -98,7 +99,8 @@ module Tapioca
|
|
98
99
|
|
99
100
|
class << self
|
100
101
|
extend T::Sig
|
101
|
-
|
102
|
+
# @override
|
103
|
+
#: -> T::Enumerable[Module]
|
102
104
|
def gather_constants
|
103
105
|
return [] unless defined?(Rails.application) && Rails.application
|
104
106
|
|
@@ -130,7 +132,7 @@ module Tapioca
|
|
130
132
|
constants.concat(NON_DISCOVERABLE_INCLUDERS).push(GeneratedUrlHelpersModule, GeneratedPathHelpersModule)
|
131
133
|
end
|
132
134
|
|
133
|
-
|
135
|
+
#: -> Array[Module]
|
134
136
|
def gather_non_discoverable_includers
|
135
137
|
[].tap do |includers|
|
136
138
|
if defined?(ActionController::TemplateAssertions) && defined?(ActionDispatch::IntegrationTest)
|
@@ -145,7 +147,7 @@ module Tapioca
|
|
145
147
|
|
146
148
|
# Returns `true` if `mod` "directly" includes `helper`.
|
147
149
|
# For classes, this method will return false if the `helper` is included only by a superclass
|
148
|
-
|
150
|
+
#: (Module mod, Module helper) -> bool
|
149
151
|
private def includes_helper?(mod, helper)
|
150
152
|
ancestors = ancestors_of(mod)
|
151
153
|
|
@@ -160,11 +162,11 @@ module Tapioca
|
|
160
162
|
end
|
161
163
|
end
|
162
164
|
|
163
|
-
NON_DISCOVERABLE_INCLUDERS =
|
165
|
+
NON_DISCOVERABLE_INCLUDERS = gather_non_discoverable_includers #: Array[Module]
|
164
166
|
|
165
167
|
private
|
166
168
|
|
167
|
-
|
169
|
+
#: (RBI::Tree root, Module constant) -> void
|
168
170
|
def generate_module_for(root, constant)
|
169
171
|
root.create_module(T.must(constant.name)) do |mod|
|
170
172
|
mod.create_include("::ActionDispatch::Routing::UrlFor")
|
@@ -180,7 +182,7 @@ module Tapioca
|
|
180
182
|
end
|
181
183
|
end
|
182
184
|
|
183
|
-
|
185
|
+
#: (RBI::Scope mod, Module helper_module) -> void
|
184
186
|
def create_mixins_for(mod, helper_module)
|
185
187
|
include_helper = constant.ancestors.include?(helper_module) || NON_DISCOVERABLE_INCLUDERS.include?(constant)
|
186
188
|
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
|
@@ -10,7 +10,7 @@ module Tapioca
|
|
10
10
|
|
11
11
|
# Returns the type indicated by the custom ActiveModel::Type::Value.
|
12
12
|
# Accepts subclasses of ActiveModel::Type::Value as well as classes that implement similar methods.
|
13
|
-
|
13
|
+
#: (untyped type_value) -> String
|
14
14
|
def type_for(type_value)
|
15
15
|
return "T.untyped" if Runtime::GenericTypeRegistry.generic_type_instance?(type_value)
|
16
16
|
|
@@ -23,34 +23,31 @@ module Tapioca
|
|
23
23
|
type.to_s
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
#: (untyped type_value) -> bool
|
27
27
|
def assume_nilable?(type_value)
|
28
28
|
!type_value.respond_to?(:__tapioca_type)
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
-
MEANINGLESS_TYPES =
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
].freeze,
|
40
|
-
T::Array[Object],
|
41
|
-
)
|
33
|
+
MEANINGLESS_TYPES = [
|
34
|
+
T.untyped,
|
35
|
+
T.noreturn,
|
36
|
+
T::Private::Types::Void,
|
37
|
+
T::Private::Types::NotTyped,
|
38
|
+
].freeze #: Array[Object]
|
42
39
|
|
43
|
-
|
40
|
+
#: (untyped type) -> bool
|
44
41
|
def meaningful_type?(type)
|
45
42
|
!MEANINGLESS_TYPES.include?(type)
|
46
43
|
end
|
47
44
|
|
48
|
-
|
45
|
+
#: (untyped obj) -> T::Types::Base?
|
49
46
|
def lookup_tapioca_type(obj)
|
50
47
|
T::Utils.coerce(obj.__tapioca_type) if obj.respond_to?(:__tapioca_type)
|
51
48
|
end
|
52
49
|
|
53
|
-
|
50
|
+
#: (untyped obj, Symbol method) -> T::Types::Base?
|
54
51
|
def lookup_return_type_of_method(obj, method)
|
55
52
|
return_type = lookup_signature_of_method(obj, method)&.return_type
|
56
53
|
return unless return_type && meaningful_type?(return_type)
|
@@ -58,7 +55,7 @@ module Tapioca
|
|
58
55
|
return_type
|
59
56
|
end
|
60
57
|
|
61
|
-
|
58
|
+
#: (untyped obj, Symbol method) -> T::Types::Base?
|
62
59
|
def lookup_arg_type_of_method(obj, method)
|
63
60
|
# Arg types is an array of [name, type] entries, so we dig into first entry (index 0)
|
64
61
|
# and then into the type which is the last element (index 1)
|
@@ -68,7 +65,7 @@ module Tapioca
|
|
68
65
|
first_arg_type
|
69
66
|
end
|
70
67
|
|
71
|
-
|
68
|
+
#: (untyped obj, Symbol method) -> untyped
|
72
69
|
def lookup_signature_of_method(obj, method)
|
73
70
|
Runtime::Reflection.signature_of(obj.method(method))
|
74
71
|
rescue NameError
|
@@ -22,12 +22,7 @@ module Tapioca
|
|
22
22
|
class << self
|
23
23
|
extend T::Sig
|
24
24
|
|
25
|
-
|
26
|
-
params(
|
27
|
-
options: T::Hash[String, T.untyped],
|
28
|
-
block: T.proc.params(value: String, default_column_type_option: ColumnTypeOption).void,
|
29
|
-
).returns(ColumnTypeOption)
|
30
|
-
end
|
25
|
+
#: (Hash[String, untyped] options) { (String value, ColumnTypeOption default_column_type_option) -> void } -> ColumnTypeOption
|
31
26
|
def from_options(options, &block)
|
32
27
|
column_type_option = Persisted
|
33
28
|
value = options["ActiveRecordColumnTypes"]
|
@@ -44,39 +39,29 @@ module Tapioca
|
|
44
39
|
end
|
45
40
|
end
|
46
41
|
|
47
|
-
|
42
|
+
#: -> bool
|
48
43
|
def persisted?
|
49
44
|
self == ColumnTypeOption::Persisted
|
50
45
|
end
|
51
46
|
|
52
|
-
|
47
|
+
#: -> bool
|
53
48
|
def nilable?
|
54
49
|
self == ColumnTypeOption::Nilable
|
55
50
|
end
|
56
51
|
|
57
|
-
|
52
|
+
#: -> bool
|
58
53
|
def untyped?
|
59
54
|
self == ColumnTypeOption::Untyped
|
60
55
|
end
|
61
56
|
end
|
62
57
|
|
63
|
-
|
64
|
-
params(
|
65
|
-
constant: T.class_of(ActiveRecord::Base),
|
66
|
-
column_type_option: ColumnTypeOption,
|
67
|
-
).void
|
68
|
-
end
|
58
|
+
#: (singleton(ActiveRecord::Base) constant, ?column_type_option: ColumnTypeOption) -> void
|
69
59
|
def initialize(constant, column_type_option: ColumnTypeOption::Persisted)
|
70
60
|
@constant = constant
|
71
61
|
@column_type_option = column_type_option
|
72
62
|
end
|
73
63
|
|
74
|
-
|
75
|
-
params(
|
76
|
-
attribute_name: String,
|
77
|
-
column_name: String,
|
78
|
-
).returns([String, String])
|
79
|
-
end
|
64
|
+
#: (String attribute_name, ?String column_name) -> [String, String]
|
80
65
|
def type_for(attribute_name, column_name = attribute_name)
|
81
66
|
return id_type if attribute_name == "id"
|
82
67
|
|
@@ -85,7 +70,7 @@ module Tapioca
|
|
85
70
|
|
86
71
|
private
|
87
72
|
|
88
|
-
|
73
|
+
#: -> [String, String]
|
89
74
|
def id_type
|
90
75
|
if @constant.respond_to?(:composite_primary_key?) && T.unsafe(@constant).composite_primary_key?
|
91
76
|
primary_key_columns = @constant.primary_key
|
@@ -105,7 +90,7 @@ module Tapioca
|
|
105
90
|
end
|
106
91
|
end
|
107
92
|
|
108
|
-
|
93
|
+
#: (String? column_name) -> [String, String]
|
109
94
|
def column_type_for(column_name)
|
110
95
|
return ["T.untyped", "T.untyped"] if @column_type_option.untyped?
|
111
96
|
|
@@ -128,7 +113,7 @@ module Tapioca
|
|
128
113
|
end
|
129
114
|
end
|
130
115
|
|
131
|
-
|
116
|
+
#: (untyped column_type, column_nullability: bool) -> String
|
132
117
|
def type_for_activerecord_value(column_type, column_nullability:)
|
133
118
|
case column_type
|
134
119
|
when ->(type) { defined?(MoneyColumn) && MoneyColumn::ActiveRecordType === type }
|
@@ -229,7 +214,7 @@ module Tapioca
|
|
229
214
|
end
|
230
215
|
end
|
231
216
|
|
232
|
-
|
217
|
+
#: (String base_type, column_nullability: bool) -> String
|
233
218
|
def as_non_nilable_if_persisted_and_not_nullable(base_type, column_nullability:)
|
234
219
|
# It's possible that when ActiveModel::Type::Value is used, the signature being reflected on in
|
235
220
|
# ActiveModelTypeHelper.type_for(type_value) may say the type can be nilable. However, if the type is
|
@@ -239,7 +224,7 @@ module Tapioca
|
|
239
224
|
base_type
|
240
225
|
end
|
241
226
|
|
242
|
-
|
227
|
+
#: (ActiveRecord::Enum::EnumType column_type) -> String
|
243
228
|
def enum_setter_type(column_type)
|
244
229
|
# In Rails < 7 this method is private. When support for that is dropped we can call the method directly
|
245
230
|
case column_type.send(:subtype)
|
@@ -250,7 +235,7 @@ module Tapioca
|
|
250
235
|
end
|
251
236
|
end
|
252
237
|
|
253
|
-
|
238
|
+
#: (ActiveRecord::Type::Serialized column_type) -> String
|
254
239
|
def serialized_column_type(column_type)
|
255
240
|
case column_type.coder
|
256
241
|
when ActiveRecord::Coders::YAMLColumn
|
@@ -267,7 +252,7 @@ module Tapioca
|
|
267
252
|
end
|
268
253
|
end
|
269
254
|
|
270
|
-
|
255
|
+
#: (untyped column_type) -> bool
|
271
256
|
def not_nilable_serialized_column?(column_type)
|
272
257
|
return false unless column_type.is_a?(ActiveRecord::Type::Serialized)
|
273
258
|
return false unless column_type.coder.is_a?(ActiveRecord::Coders::YAMLColumn)
|
@@ -11,23 +11,27 @@ module Tapioca
|
|
11
11
|
T.any(::ActiveRecord::Reflection::ThroughReflection, ::ActiveRecord::Reflection::AssociationReflection)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
AssociationMethodsModuleName = T.let("GeneratedAssociationMethods", String)
|
16
|
-
DelegatedTypesModuleName = T.let("GeneratedDelegatedTypeMethods", String)
|
17
|
-
SecureTokensModuleName = T.let("GeneratedSecureTokenMethods", String)
|
18
|
-
StoredAttributesModuleName = T.let("GeneratedStoredAttributesMethods", String)
|
14
|
+
# rubocop:disable Naming/ConstantName
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
AttributeMethodsModuleName = "GeneratedAttributeMethods" #: String
|
17
|
+
AssociationMethodsModuleName = "GeneratedAssociationMethods" #: String
|
18
|
+
DelegatedTypesModuleName = "GeneratedDelegatedTypeMethods" #: String
|
19
|
+
SecureTokensModuleName = "GeneratedSecureTokenMethods" #: String
|
20
|
+
StoredAttributesModuleName = "GeneratedStoredAttributesMethods" #: String
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
RelationMethodsModuleName = "GeneratedRelationMethods" #: String
|
23
|
+
AssociationRelationMethodsModuleName = "GeneratedAssociationRelationMethods" #: String
|
24
|
+
CommonRelationMethodsModuleName = "CommonRelationMethods" #: String
|
25
|
+
|
26
|
+
RelationClassName = "PrivateRelation" #: String
|
27
|
+
RelationGroupChainClassName = "PrivateRelationGroupChain" #: String
|
28
|
+
RelationWhereChainClassName = "PrivateRelationWhereChain" #: String
|
29
|
+
AssociationRelationClassName = "PrivateAssociationRelation" #: String
|
30
|
+
AssociationRelationGroupChainClassName = "PrivateAssociationRelationGroupChain" #: String
|
31
|
+
AssociationRelationWhereChainClassName = "PrivateAssociationRelationWhereChain" #: String
|
32
|
+
AssociationsCollectionProxyClassName = "PrivateCollectionProxy" #: String
|
33
|
+
|
34
|
+
# rubocop:enable Naming/ConstantName
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
@@ -9,12 +9,7 @@ module Tapioca
|
|
9
9
|
|
10
10
|
extend T::Sig
|
11
11
|
|
12
|
-
|
13
|
-
params(
|
14
|
-
argument: GraphQL::Schema::Argument,
|
15
|
-
constant: T.any(T.class_of(GraphQL::Schema::Mutation), T.class_of(GraphQL::Schema::InputObject)),
|
16
|
-
).returns(String)
|
17
|
-
end
|
12
|
+
#: (GraphQL::Schema::Argument argument, (singleton(GraphQL::Schema::Mutation) | singleton(GraphQL::Schema::InputObject)) constant) -> String
|
18
13
|
def type_for_argument(argument, constant)
|
19
14
|
type = if argument.loads
|
20
15
|
loads_type = ::GraphQL::Schema::Wrapper.new(argument.loads)
|
@@ -39,21 +34,7 @@ module Tapioca
|
|
39
34
|
)
|
40
35
|
end
|
41
36
|
|
42
|
-
|
43
|
-
params(
|
44
|
-
type: T.any(
|
45
|
-
GraphQL::Schema::Wrapper,
|
46
|
-
T.class_of(GraphQL::Schema::Scalar),
|
47
|
-
T.class_of(GraphQL::Schema::Enum),
|
48
|
-
T.class_of(GraphQL::Schema::Union),
|
49
|
-
T.class_of(GraphQL::Schema::Object),
|
50
|
-
T.class_of(GraphQL::Schema::Interface),
|
51
|
-
T.class_of(GraphQL::Schema::InputObject),
|
52
|
-
),
|
53
|
-
ignore_nilable_wrapper: T::Boolean,
|
54
|
-
prepare_method: T.nilable(Method),
|
55
|
-
).returns(String)
|
56
|
-
end
|
37
|
+
#: ((GraphQL::Schema::Wrapper | singleton(GraphQL::Schema::Scalar) | singleton(GraphQL::Schema::Enum) | singleton(GraphQL::Schema::Union) | singleton(GraphQL::Schema::Object) | singleton(GraphQL::Schema::Interface) | singleton(GraphQL::Schema::InputObject)) type, ?ignore_nilable_wrapper: bool, ?prepare_method: Method?) -> String
|
57
38
|
def type_for(type, ignore_nilable_wrapper: false, prepare_method: nil)
|
58
39
|
unwrapped_type = type.unwrap
|
59
40
|
|
@@ -116,7 +97,7 @@ module Tapioca
|
|
116
97
|
|
117
98
|
private
|
118
99
|
|
119
|
-
|
100
|
+
#: (Module constant) -> String
|
120
101
|
def type_for_constant(constant)
|
121
102
|
if constant.instance_methods.include?(:prepare)
|
122
103
|
prepare_method = constant.instance_method(:prepare)
|
@@ -129,12 +110,12 @@ module Tapioca
|
|
129
110
|
Runtime::Reflection.qualified_name_of(constant) || "T.untyped"
|
130
111
|
end
|
131
112
|
|
132
|
-
|
113
|
+
#: (GraphQL::Schema::Argument argument) -> bool
|
133
114
|
def has_replaceable_default?(argument)
|
134
115
|
!!argument.replace_null_with_default? && !argument.default_value.nil?
|
135
116
|
end
|
136
117
|
|
137
|
-
|
118
|
+
#: (T::Types::Base? return_type) -> bool
|
138
119
|
def valid_return_type?(return_type)
|
139
120
|
!!return_type && !(T::Private::Types::Void === return_type || T::Private::Types::NotTyped === return_type)
|
140
121
|
end
|