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
|
@@ -81,12 +81,12 @@ module Tapioca
|
|
|
81
81
|
# end
|
|
82
82
|
# end
|
|
83
83
|
# ~~~
|
|
84
|
+
#: [ConstantType = singleton(::ActiveRecord::Base)]
|
|
84
85
|
class ActiveRecordTypedStore < Compiler
|
|
85
86
|
extend T::Sig
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
sig { override.void }
|
|
88
|
+
# @override
|
|
89
|
+
#: -> void
|
|
90
90
|
def decorate
|
|
91
91
|
stores = constant.typed_stores
|
|
92
92
|
return if stores.values.all? { |store| store.accessors.empty? }
|
|
@@ -110,7 +110,8 @@ module Tapioca
|
|
|
110
110
|
class << self
|
|
111
111
|
extend T::Sig
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
# @override
|
|
114
|
+
#: -> T::Enumerable[Module]
|
|
114
115
|
def gather_constants
|
|
115
116
|
descendants_of(::ActiveRecord::Base).select do |klass|
|
|
116
117
|
klass.include?(ActiveRecord::TypedStore::Behavior)
|
|
@@ -120,22 +121,19 @@ module Tapioca
|
|
|
120
121
|
|
|
121
122
|
private
|
|
122
123
|
|
|
123
|
-
TYPES =
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
sig { params(field: ActiveRecord::TypedStore::Field).returns(String) }
|
|
124
|
+
TYPES = {
|
|
125
|
+
boolean: "T::Boolean",
|
|
126
|
+
integer: "Integer",
|
|
127
|
+
string: "String",
|
|
128
|
+
float: "Float",
|
|
129
|
+
date: "Date",
|
|
130
|
+
time: "Time",
|
|
131
|
+
datetime: "DateTime",
|
|
132
|
+
decimal: "BigDecimal",
|
|
133
|
+
any: "T.untyped",
|
|
134
|
+
}.freeze #: Hash[Symbol, String]
|
|
135
|
+
|
|
136
|
+
#: (ActiveRecord::TypedStore::Field field) -> String
|
|
139
137
|
def type_for(field)
|
|
140
138
|
type = TYPES.fetch(field.type_sym, "T.untyped")
|
|
141
139
|
|
|
@@ -154,14 +152,7 @@ module Tapioca
|
|
|
154
152
|
type
|
|
155
153
|
end
|
|
156
154
|
|
|
157
|
-
|
|
158
|
-
params(
|
|
159
|
-
klass: RBI::Scope,
|
|
160
|
-
name: String,
|
|
161
|
-
type: String,
|
|
162
|
-
)
|
|
163
|
-
.void
|
|
164
|
-
end
|
|
155
|
+
#: (RBI::Scope klass, String name, String type) -> void
|
|
165
156
|
def generate_methods(klass, name, type)
|
|
166
157
|
klass.create_method(
|
|
167
158
|
"#{name}=",
|
|
@@ -54,12 +54,12 @@ module Tapioca
|
|
|
54
54
|
# def year?; end
|
|
55
55
|
# end
|
|
56
56
|
# ~~~
|
|
57
|
+
#: [ConstantType = singleton(::ActiveResource::Base)]
|
|
57
58
|
class ActiveResource < Compiler
|
|
58
59
|
extend T::Sig
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
sig { override.void }
|
|
61
|
+
# @override
|
|
62
|
+
#: -> void
|
|
63
63
|
def decorate
|
|
64
64
|
return if constant.schema.blank?
|
|
65
65
|
|
|
@@ -73,7 +73,8 @@ module Tapioca
|
|
|
73
73
|
class << self
|
|
74
74
|
extend T::Sig
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
# @override
|
|
77
|
+
#: -> T::Enumerable[Module]
|
|
77
78
|
def gather_constants
|
|
78
79
|
descendants_of(::ActiveResource::Base)
|
|
79
80
|
end
|
|
@@ -81,28 +82,25 @@ module Tapioca
|
|
|
81
82
|
|
|
82
83
|
private
|
|
83
84
|
|
|
84
|
-
TYPES =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}.freeze,
|
|
97
|
-
T::Hash[Symbol, String],
|
|
98
|
-
)
|
|
85
|
+
TYPES = {
|
|
86
|
+
boolean: "T::Boolean",
|
|
87
|
+
integer: "Integer",
|
|
88
|
+
string: "String",
|
|
89
|
+
float: "Float",
|
|
90
|
+
date: "Date",
|
|
91
|
+
time: "Time",
|
|
92
|
+
datetime: "DateTime",
|
|
93
|
+
decimal: "BigDecimal",
|
|
94
|
+
binary: "String",
|
|
95
|
+
text: "String",
|
|
96
|
+
}.freeze #: Hash[Symbol, String]
|
|
99
97
|
|
|
100
|
-
|
|
98
|
+
#: (Symbol attr_type) -> String
|
|
101
99
|
def type_for(attr_type)
|
|
102
100
|
TYPES.fetch(attr_type, "T.untyped")
|
|
103
101
|
end
|
|
104
102
|
|
|
105
|
-
|
|
103
|
+
#: (RBI::Scope klass, String attribute, String type) -> void
|
|
106
104
|
def create_schema_methods(klass, attribute, type)
|
|
107
105
|
return_type = type_for(type.to_sym)
|
|
108
106
|
|
|
@@ -38,19 +38,12 @@ module Tapioca
|
|
|
38
38
|
# def photo=(attachable); end
|
|
39
39
|
# end
|
|
40
40
|
# ~~~
|
|
41
|
+
#: [ConstantType = (Module & ::ActiveStorage::Reflection::ActiveRecordExtensions::ClassMethods)]
|
|
41
42
|
class ActiveStorage < Compiler
|
|
42
43
|
extend T::Sig
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
fixed: T.all(
|
|
47
|
-
Module,
|
|
48
|
-
::ActiveStorage::Reflection::ActiveRecordExtensions::ClassMethods,
|
|
49
|
-
),
|
|
50
|
-
}
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
sig { override.void }
|
|
45
|
+
# @override
|
|
46
|
+
#: -> void
|
|
54
47
|
def decorate
|
|
55
48
|
return if constant.reflect_on_all_attachments.empty?
|
|
56
49
|
|
|
@@ -74,7 +67,8 @@ module Tapioca
|
|
|
74
67
|
class << self
|
|
75
68
|
extend T::Sig
|
|
76
69
|
|
|
77
|
-
|
|
70
|
+
# @override
|
|
71
|
+
#: -> T::Enumerable[Module]
|
|
78
72
|
def gather_constants
|
|
79
73
|
descendants_of(::ActiveRecord::Base)
|
|
80
74
|
.reject(&:abstract_class?)
|
|
@@ -84,9 +78,7 @@ module Tapioca
|
|
|
84
78
|
|
|
85
79
|
private
|
|
86
80
|
|
|
87
|
-
|
|
88
|
-
params(reflection: ActiveRecord::Reflection::MacroReflection).returns(String)
|
|
89
|
-
end
|
|
81
|
+
#: (ActiveRecord::Reflection::MacroReflection reflection) -> String
|
|
90
82
|
def type_of(reflection)
|
|
91
83
|
case reflection
|
|
92
84
|
when ::ActiveStorage::Reflection::HasOneAttachedReflection
|
|
@@ -37,12 +37,12 @@ module Tapioca
|
|
|
37
37
|
# mixes_in_class_methods(::Foo::ClassMethods)
|
|
38
38
|
# end
|
|
39
39
|
# ~~~
|
|
40
|
+
#: [ConstantType = Module]
|
|
40
41
|
class ActiveSupportConcern < Compiler
|
|
41
42
|
extend T::Sig
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
sig { override.void }
|
|
44
|
+
# @override
|
|
45
|
+
#: -> void
|
|
46
46
|
def decorate
|
|
47
47
|
dependencies = linearized_dependencies
|
|
48
48
|
|
|
@@ -64,7 +64,8 @@ module Tapioca
|
|
|
64
64
|
class << self
|
|
65
65
|
extend T::Sig
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
# @override
|
|
68
|
+
#: -> T::Enumerable[Module]
|
|
68
69
|
def gather_constants
|
|
69
70
|
all_modules.select do |mod|
|
|
70
71
|
name_of(mod) && # i.e. not anonymous
|
|
@@ -75,10 +76,10 @@ module Tapioca
|
|
|
75
76
|
end
|
|
76
77
|
|
|
77
78
|
# Returns true when `mod` includes other concerns
|
|
78
|
-
|
|
79
|
+
#: (Module mod) -> bool
|
|
79
80
|
def has_dependencies?(mod) = dependencies_of(mod).any?
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
#: (Module concern) -> Array[Module]
|
|
82
83
|
def dependencies_of(concern)
|
|
83
84
|
concern.instance_variable_get(:@_dependencies) || []
|
|
84
85
|
end
|
|
@@ -86,12 +87,12 @@ module Tapioca
|
|
|
86
87
|
|
|
87
88
|
private
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
#: (Module concern) -> Array[Module]
|
|
90
91
|
def dependencies_of(concern)
|
|
91
92
|
self.class.dependencies_of(concern)
|
|
92
93
|
end
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
#: (?Module concern) -> Array[Module]
|
|
95
96
|
def linearized_dependencies(concern = constant)
|
|
96
97
|
# Grab all the dependencies of the concern
|
|
97
98
|
dependencies = dependencies_of(concern)
|
|
@@ -59,12 +59,12 @@ module Tapioca
|
|
|
59
59
|
# end
|
|
60
60
|
# end
|
|
61
61
|
# ~~~
|
|
62
|
+
#: [ConstantType = singleton(::ActiveSupport::CurrentAttributes)]
|
|
62
63
|
class ActiveSupportCurrentAttributes < Compiler
|
|
63
64
|
extend T::Sig
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
sig { override.void }
|
|
66
|
+
# @override
|
|
67
|
+
#: -> void
|
|
68
68
|
def decorate
|
|
69
69
|
dynamic_methods = dynamic_methods_of_constant
|
|
70
70
|
instance_methods = instance_methods_of_constant - dynamic_methods
|
|
@@ -96,7 +96,8 @@ module Tapioca
|
|
|
96
96
|
class << self
|
|
97
97
|
extend T::Sig
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
# @override
|
|
100
|
+
#: -> T::Enumerable[Module]
|
|
100
101
|
def gather_constants
|
|
101
102
|
descendants_of(::ActiveSupport::CurrentAttributes)
|
|
102
103
|
end
|
|
@@ -104,17 +105,17 @@ module Tapioca
|
|
|
104
105
|
|
|
105
106
|
private
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
#: -> Array[Symbol]
|
|
108
109
|
def dynamic_methods_of_constant
|
|
109
110
|
constant.instance_variable_get(:@generated_attribute_methods)&.instance_methods(false) || []
|
|
110
111
|
end
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
#: -> Array[Symbol]
|
|
113
114
|
def instance_methods_of_constant
|
|
114
115
|
constant.instance_methods(false)
|
|
115
116
|
end
|
|
116
117
|
|
|
117
|
-
|
|
118
|
+
#: (RBI::Scope klass, String method, class_method: bool) -> void
|
|
118
119
|
def generate_method(klass, method, class_method:)
|
|
119
120
|
method_def = if class_method
|
|
120
121
|
constant.method(method)
|
|
@@ -34,12 +34,12 @@ module Tapioca
|
|
|
34
34
|
# end
|
|
35
35
|
# end
|
|
36
36
|
# ```
|
|
37
|
+
#: [ConstantType = singleton(::Time)]
|
|
37
38
|
class ActiveSupportTimeExt < Compiler
|
|
38
39
|
extend T::Sig
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
sig { override.void }
|
|
41
|
+
# @override
|
|
42
|
+
#: -> void
|
|
43
43
|
def decorate
|
|
44
44
|
return unless constant.respond_to?(:zone)
|
|
45
45
|
|
|
@@ -57,7 +57,8 @@ module Tapioca
|
|
|
57
57
|
class << self
|
|
58
58
|
extend T::Sig
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
# @override
|
|
61
|
+
#: -> T::Enumerable[Module]
|
|
61
62
|
def gather_constants
|
|
62
63
|
[::Time]
|
|
63
64
|
end
|
|
@@ -40,14 +40,14 @@ module Tapioca
|
|
|
40
40
|
# def github=(value); end
|
|
41
41
|
# end
|
|
42
42
|
# ```
|
|
43
|
+
#: [ConstantType = Module]
|
|
43
44
|
class Config < Compiler
|
|
44
45
|
extend T::Sig
|
|
45
46
|
|
|
46
47
|
CONFIG_OPTIONS_SUFFIX = "ConfigOptions"
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
sig { override.void }
|
|
49
|
+
# @override
|
|
50
|
+
#: -> void
|
|
51
51
|
def decorate
|
|
52
52
|
# The constant we are given is the specialized config options type
|
|
53
53
|
option_class_name = constant.name
|
|
@@ -95,7 +95,8 @@ module Tapioca
|
|
|
95
95
|
class << self
|
|
96
96
|
extend T::Sig
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
# @override
|
|
99
|
+
#: -> T::Enumerable[Module]
|
|
99
100
|
def gather_constants
|
|
100
101
|
name = ::Config.const_name
|
|
101
102
|
return [] unless Object.const_defined?(name)
|
|
@@ -58,12 +58,12 @@ module Tapioca
|
|
|
58
58
|
# end
|
|
59
59
|
# end
|
|
60
60
|
# ~~~
|
|
61
|
+
#: [ConstantType = (singleton(::FrozenRecord::Base) & Extensions::FrozenRecord)]
|
|
61
62
|
class FrozenRecord < Compiler
|
|
62
63
|
extend T::Sig
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
sig { override.void }
|
|
65
|
+
# @override
|
|
66
|
+
#: -> void
|
|
67
67
|
def decorate
|
|
68
68
|
attributes = constant.attributes
|
|
69
69
|
return if attributes.empty?
|
|
@@ -87,7 +87,8 @@ module Tapioca
|
|
|
87
87
|
class << self
|
|
88
88
|
extend T::Sig
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
# @override
|
|
91
|
+
#: -> T::Enumerable[Module]
|
|
91
92
|
def gather_constants
|
|
92
93
|
descendants_of(::FrozenRecord::Base).reject(&:abstract_class?)
|
|
93
94
|
end
|
|
@@ -95,7 +96,7 @@ module Tapioca
|
|
|
95
96
|
|
|
96
97
|
private
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
#: (RBI::Scope record) -> void
|
|
99
100
|
def decorate_scopes(record)
|
|
100
101
|
scopes = constant.__tapioca_scope_names
|
|
101
102
|
return if scopes.nil?
|
|
@@ -111,12 +112,7 @@ module Tapioca
|
|
|
111
112
|
record.create_extend(module_name)
|
|
112
113
|
end
|
|
113
114
|
|
|
114
|
-
|
|
115
|
-
params(
|
|
116
|
-
scope_method: String,
|
|
117
|
-
mod: RBI::Scope,
|
|
118
|
-
).void
|
|
119
|
-
end
|
|
115
|
+
#: (String scope_method, RBI::Scope mod) -> void
|
|
120
116
|
def generate_scope_method(scope_method, mod)
|
|
121
117
|
mod.create_method(
|
|
122
118
|
scope_method,
|
|
@@ -34,12 +34,12 @@ module Tapioca
|
|
|
34
34
|
# def post_id; end
|
|
35
35
|
# end
|
|
36
36
|
# ~~~
|
|
37
|
+
#: [ConstantType = singleton(GraphQL::Schema::InputObject)]
|
|
37
38
|
class GraphqlInputObject < Compiler
|
|
38
39
|
extend T::Sig
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
sig { override.void }
|
|
41
|
+
# @override
|
|
42
|
+
#: -> void
|
|
43
43
|
def decorate
|
|
44
44
|
# Skip methods explicitly defined in code
|
|
45
45
|
arguments = constant.all_argument_definitions.select do |argument|
|
|
@@ -61,15 +61,13 @@ module Tapioca
|
|
|
61
61
|
|
|
62
62
|
private
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
#: -> String?
|
|
65
65
|
def graphql_input_object_argument_source_file
|
|
66
|
-
@graphql_input_object_argument_source_file ||=
|
|
67
|
-
GraphQL::Schema::InputObject.method(:argument).source_location&.first
|
|
68
|
-
T.nilable(String),
|
|
69
|
-
)
|
|
66
|
+
@graphql_input_object_argument_source_file ||=
|
|
67
|
+
GraphQL::Schema::InputObject.method(:argument).source_location&.first #: String?
|
|
70
68
|
end
|
|
71
69
|
|
|
72
|
-
|
|
70
|
+
#: (String method_name) -> bool
|
|
73
71
|
def method_defined_by_graphql?(method_name)
|
|
74
72
|
method_file = constant.instance_method(method_name).source_location&.first
|
|
75
73
|
!!(method_file && graphql_input_object_argument_source_file == method_file)
|
|
@@ -78,7 +76,8 @@ module Tapioca
|
|
|
78
76
|
class << self
|
|
79
77
|
extend T::Sig
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
# @override
|
|
80
|
+
#: -> T::Enumerable[Module]
|
|
82
81
|
def gather_constants
|
|
83
82
|
all_classes.select { |c| GraphQL::Schema::InputObject > c }
|
|
84
83
|
end
|
|
@@ -35,12 +35,12 @@ module Tapioca
|
|
|
35
35
|
# def resolve(body:, post_id:); end
|
|
36
36
|
# end
|
|
37
37
|
# ~~~
|
|
38
|
+
#: [ConstantType = singleton(GraphQL::Schema::Mutation)]
|
|
38
39
|
class GraphqlMutation < Compiler
|
|
39
40
|
extend T::Sig
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
sig { override.void }
|
|
42
|
+
# @override
|
|
43
|
+
#: -> void
|
|
44
44
|
def decorate
|
|
45
45
|
return unless constant.method_defined?(:resolve)
|
|
46
46
|
|
|
@@ -63,12 +63,7 @@ module Tapioca
|
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
params(
|
|
68
|
-
argument: T.nilable(GraphQL::Schema::Argument),
|
|
69
|
-
constant: T.class_of(GraphQL::Schema::Mutation),
|
|
70
|
-
).returns(String)
|
|
71
|
-
end
|
|
66
|
+
#: (GraphQL::Schema::Argument? argument, singleton(GraphQL::Schema::Mutation) constant) -> String
|
|
72
67
|
def argument_type(argument, constant)
|
|
73
68
|
return "T.untyped" unless argument
|
|
74
69
|
|
|
@@ -78,7 +73,8 @@ module Tapioca
|
|
|
78
73
|
class << self
|
|
79
74
|
extend T::Sig
|
|
80
75
|
|
|
81
|
-
|
|
76
|
+
# @override
|
|
77
|
+
#: -> T::Enumerable[Module]
|
|
82
78
|
def gather_constants
|
|
83
79
|
all_classes.select { |c| GraphQL::Schema::Mutation > c && GraphQL::Schema::RelayClassicMutation != c }
|
|
84
80
|
end
|
|
@@ -55,17 +55,14 @@ module Tapioca
|
|
|
55
55
|
# def fetch_by_title_and_review_date(title, review_date, includes: nil); end
|
|
56
56
|
# end
|
|
57
57
|
# ~~~
|
|
58
|
+
#: [ConstantType = singleton(::ActiveRecord::Base)]
|
|
58
59
|
class IdentityCache < Compiler
|
|
59
60
|
extend T::Sig
|
|
60
61
|
|
|
61
|
-
COLLECTION_TYPE = T
|
|
62
|
-
->(type) { "T::Array[::#{type}]" },
|
|
63
|
-
T.proc.params(type: T.any(Module, String)).returns(String),
|
|
64
|
-
)
|
|
62
|
+
COLLECTION_TYPE = ->(type) { "T::Array[::#{type}]" } #: ^((Module | String) type) -> String
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
sig { override.void }
|
|
64
|
+
# @override
|
|
65
|
+
#: -> void
|
|
69
66
|
def decorate
|
|
70
67
|
caches = constant.send(:all_cached_associations)
|
|
71
68
|
cache_indexes = constant.send(:cache_indexes)
|
|
@@ -97,7 +94,8 @@ module Tapioca
|
|
|
97
94
|
class << self
|
|
98
95
|
extend T::Sig
|
|
99
96
|
|
|
100
|
-
|
|
97
|
+
# @override
|
|
98
|
+
#: -> T::Enumerable[Module]
|
|
101
99
|
def gather_constants
|
|
102
100
|
descendants_of(::ActiveRecord::Base).select do |klass|
|
|
103
101
|
::IdentityCache::WithoutPrimaryIndex > klass
|
|
@@ -107,12 +105,7 @@ module Tapioca
|
|
|
107
105
|
|
|
108
106
|
private
|
|
109
107
|
|
|
110
|
-
|
|
111
|
-
params(
|
|
112
|
-
field: T.untyped,
|
|
113
|
-
returns_collection: T::Boolean,
|
|
114
|
-
).returns(String)
|
|
115
|
-
end
|
|
108
|
+
#: (untyped field, returns_collection: bool) -> String
|
|
116
109
|
def type_for_field(field, returns_collection:)
|
|
117
110
|
cache_type = field.reflection.compute_class(field.reflection.class_name)
|
|
118
111
|
if returns_collection
|
|
@@ -124,13 +117,7 @@ module Tapioca
|
|
|
124
117
|
"T.untyped"
|
|
125
118
|
end
|
|
126
119
|
|
|
127
|
-
|
|
128
|
-
params(
|
|
129
|
-
field: T.untyped,
|
|
130
|
-
klass: RBI::Scope,
|
|
131
|
-
returns_collection: T::Boolean,
|
|
132
|
-
).void
|
|
133
|
-
end
|
|
120
|
+
#: (untyped field, RBI::Scope klass, returns_collection: bool) -> void
|
|
134
121
|
def create_fetch_field_methods(field, klass, returns_collection:)
|
|
135
122
|
name = field.cached_accessor_name.to_s
|
|
136
123
|
type = type_for_field(field, returns_collection: returns_collection)
|
|
@@ -143,12 +130,7 @@ module Tapioca
|
|
|
143
130
|
end
|
|
144
131
|
end
|
|
145
132
|
|
|
146
|
-
|
|
147
|
-
params(
|
|
148
|
-
field: T.untyped,
|
|
149
|
-
klass: RBI::Scope,
|
|
150
|
-
).void
|
|
151
|
-
end
|
|
133
|
+
#: (untyped field, RBI::Scope klass) -> void
|
|
152
134
|
def create_fetch_by_methods(field, klass)
|
|
153
135
|
is_cache_index = field.instance_variable_defined?(:@attribute_proc)
|
|
154
136
|
|
|
@@ -159,12 +141,7 @@ module Tapioca
|
|
|
159
141
|
create_index_fetch_by_methods(field, klass) if is_cache_index
|
|
160
142
|
end
|
|
161
143
|
|
|
162
|
-
|
|
163
|
-
params(
|
|
164
|
-
field: T.untyped,
|
|
165
|
-
klass: RBI::Scope,
|
|
166
|
-
).void
|
|
167
|
-
end
|
|
144
|
+
#: (untyped field, RBI::Scope klass) -> void
|
|
168
145
|
def create_index_fetch_by_methods(field, klass)
|
|
169
146
|
fields_name = field.key_fields.join("_and_")
|
|
170
147
|
name = "fetch_by_#{fields_name}"
|
|
@@ -209,12 +186,7 @@ module Tapioca
|
|
|
209
186
|
)
|
|
210
187
|
end
|
|
211
188
|
|
|
212
|
-
|
|
213
|
-
params(
|
|
214
|
-
field: T.untyped,
|
|
215
|
-
klass: RBI::Scope,
|
|
216
|
-
).void
|
|
217
|
-
end
|
|
189
|
+
#: (untyped field, RBI::Scope klass) -> void
|
|
218
190
|
def create_aliased_fetch_by_methods(field, klass)
|
|
219
191
|
type, _ = Helpers::ActiveRecordColumnTypeHelper.new(
|
|
220
192
|
constant,
|
|
@@ -79,12 +79,12 @@ module Tapioca
|
|
|
79
79
|
# end
|
|
80
80
|
# end
|
|
81
81
|
# ~~~
|
|
82
|
+
#: [ConstantType = singleton(::JsonApiClient::Resource)]
|
|
82
83
|
class JsonApiClientResource < Compiler
|
|
83
84
|
extend T::Sig
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
sig { override.void }
|
|
86
|
+
# @override
|
|
87
|
+
#: -> void
|
|
88
88
|
def decorate
|
|
89
89
|
schema = resource_schema
|
|
90
90
|
return if schema.nil? && constant.associations.empty?
|
|
@@ -108,7 +108,8 @@ module Tapioca
|
|
|
108
108
|
class << self
|
|
109
109
|
extend T::Sig
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
# @override
|
|
112
|
+
#: -> T::Enumerable[Module]
|
|
112
113
|
def gather_constants
|
|
113
114
|
all_modules.select do |c|
|
|
114
115
|
name_of(c) && ::JsonApiClient::Resource > c
|
|
@@ -118,7 +119,7 @@ module Tapioca
|
|
|
118
119
|
|
|
119
120
|
private
|
|
120
121
|
|
|
121
|
-
|
|
122
|
+
#: -> ::JsonApiClient::Schema?
|
|
122
123
|
def resource_schema
|
|
123
124
|
schema = constant.schema
|
|
124
125
|
|
|
@@ -126,12 +127,7 @@ module Tapioca
|
|
|
126
127
|
schema if schema.size > 0 # rubocop:disable Style/ZeroLengthPredicate
|
|
127
128
|
end
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
params(
|
|
131
|
-
mod: RBI::Scope,
|
|
132
|
-
property: ::JsonApiClient::Schema::Property,
|
|
133
|
-
).void
|
|
134
|
-
end
|
|
130
|
+
#: (RBI::Scope mod, ::JsonApiClient::Schema::Property property) -> void
|
|
135
131
|
def generate_methods_for_property(mod, property)
|
|
136
132
|
type = type_for(property)
|
|
137
133
|
|
|
@@ -141,7 +137,7 @@ module Tapioca
|
|
|
141
137
|
mod.create_method("#{name}=", parameters: [create_param(name, type: type)], return_type: type)
|
|
142
138
|
end
|
|
143
139
|
|
|
144
|
-
|
|
140
|
+
#: (::JsonApiClient::Schema::Property property) -> String
|
|
145
141
|
def type_for(property)
|
|
146
142
|
type = ::JsonApiClient::Schema::TypeFactory.type_for(property.type)
|
|
147
143
|
return "T.untyped" if type.nil?
|
|
@@ -181,12 +177,7 @@ module Tapioca
|
|
|
181
177
|
end
|
|
182
178
|
end
|
|
183
179
|
|
|
184
|
-
|
|
185
|
-
params(
|
|
186
|
-
mod: RBI::Scope,
|
|
187
|
-
association: JsonApiClient::Associations::BaseAssociation,
|
|
188
|
-
).void
|
|
189
|
-
end
|
|
180
|
+
#: (RBI::Scope mod, JsonApiClient::Associations::BaseAssociation association) -> void
|
|
190
181
|
def generate_methods_for_association(mod, association)
|
|
191
182
|
# If the association is broken, it will raise a NameError when trying to access the association_class
|
|
192
183
|
klass = association.association_class
|