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
@@ -7,26 +7,26 @@ module Tapioca
|
|
7
7
|
extend T::Sig
|
8
8
|
include Runtime::Reflection
|
9
9
|
|
10
|
-
|
10
|
+
#: Array[Module]
|
11
11
|
attr_reader :dynamic_extends, :dynamic_includes
|
12
12
|
|
13
|
-
|
13
|
+
#: Array[Symbol]
|
14
14
|
attr_reader :class_attribute_readers, :class_attribute_writers, :class_attribute_predicates
|
15
15
|
|
16
|
-
|
16
|
+
#: Array[Symbol]
|
17
17
|
attr_reader :instance_attribute_readers, :instance_attribute_writers, :instance_attribute_predicates
|
18
18
|
|
19
|
-
|
19
|
+
#: (Module constant) -> void
|
20
20
|
def initialize(constant)
|
21
21
|
@constant = constant
|
22
22
|
mixins_from_modules = {}.compare_by_identity
|
23
|
-
class_attribute_readers =
|
24
|
-
class_attribute_writers =
|
25
|
-
class_attribute_predicates =
|
23
|
+
class_attribute_readers = [] #: Array[Symbol]
|
24
|
+
class_attribute_writers = [] #: Array[Symbol]
|
25
|
+
class_attribute_predicates = [] #: Array[Symbol]
|
26
26
|
|
27
|
-
instance_attribute_readers =
|
28
|
-
instance_attribute_writers =
|
29
|
-
instance_attribute_predicates =
|
27
|
+
instance_attribute_readers = [] #: Array[Symbol]
|
28
|
+
instance_attribute_writers = [] #: Array[Symbol]
|
29
|
+
instance_attribute_predicates = [] #: Array[Symbol]
|
30
30
|
|
31
31
|
Class.new do
|
32
32
|
# Override the `self.include` method
|
@@ -112,28 +112,28 @@ module Tapioca
|
|
112
112
|
# is the list of all dynamically extended modules because of that
|
113
113
|
# constant. We grab that value by deleting the key for the original
|
114
114
|
# constant.
|
115
|
-
@dynamic_extends =
|
115
|
+
@dynamic_extends = mixins_from_modules.delete(constant) || [] #: Array[Module]
|
116
116
|
|
117
117
|
# Since we deleted the original constant from the list of keys, all
|
118
118
|
# the keys that remain are the ones that are dynamically included modules
|
119
119
|
# during the include of the original constant.
|
120
|
-
@dynamic_includes =
|
120
|
+
@dynamic_includes = mixins_from_modules.keys #: Array[Module]
|
121
121
|
|
122
|
-
@class_attribute_readers =
|
123
|
-
@class_attribute_writers =
|
124
|
-
@class_attribute_predicates =
|
122
|
+
@class_attribute_readers = class_attribute_readers #: Array[Symbol]
|
123
|
+
@class_attribute_writers = class_attribute_writers #: Array[Symbol]
|
124
|
+
@class_attribute_predicates = class_attribute_predicates #: Array[Symbol]
|
125
125
|
|
126
|
-
@instance_attribute_readers =
|
127
|
-
@instance_attribute_writers =
|
128
|
-
@instance_attribute_predicates =
|
126
|
+
@instance_attribute_readers = instance_attribute_readers #: Array[Symbol]
|
127
|
+
@instance_attribute_writers = instance_attribute_writers #: Array[Symbol]
|
128
|
+
@instance_attribute_predicates = instance_attribute_predicates #: Array[Symbol]
|
129
129
|
end
|
130
130
|
|
131
|
-
|
131
|
+
#: -> bool
|
132
132
|
def empty_attributes?
|
133
133
|
@class_attribute_readers.empty? && @class_attribute_writers.empty?
|
134
134
|
end
|
135
135
|
|
136
|
-
|
136
|
+
#: (RBI::Tree tree) -> void
|
137
137
|
def compile_class_attributes(tree)
|
138
138
|
return if empty_attributes?
|
139
139
|
|
@@ -176,7 +176,7 @@ module Tapioca
|
|
176
176
|
tree << RBI::Include.new("GeneratedInstanceMethods")
|
177
177
|
end
|
178
178
|
|
179
|
-
|
179
|
+
#: (RBI::Tree tree) -> [Array[Module], Array[Module]]
|
180
180
|
def compile_mixes_in_class_methods(tree)
|
181
181
|
includes = dynamic_includes.filter_map do |mod|
|
182
182
|
qname = qualified_name_of(mod)
|
@@ -211,14 +211,14 @@ module Tapioca
|
|
211
211
|
[[], []] # silence errors
|
212
212
|
end
|
213
213
|
|
214
|
-
|
214
|
+
#: (Module mod, Array[Module] dynamic_extends) -> bool
|
215
215
|
def module_included_by_another_dynamic_extend?(mod, dynamic_extends)
|
216
216
|
dynamic_extends.any? do |dynamic_extend|
|
217
217
|
mod != dynamic_extend && ancestors_of(dynamic_extend).include?(mod)
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
221
|
-
|
221
|
+
#: (String qualified_mixin_name) -> bool
|
222
222
|
def filtered_mixin?(qualified_mixin_name)
|
223
223
|
# filter T:: namespace mixins that aren't T::Props
|
224
224
|
# T::Props and subconstants have semantic value
|
@@ -21,27 +21,22 @@ module Tapioca
|
|
21
21
|
# variable to type variable serializers. This allows us to associate type variables
|
22
22
|
# to the constant names that represent them, easily.
|
23
23
|
module GenericTypeRegistry
|
24
|
-
@generic_instances =
|
25
|
-
{},
|
26
|
-
T::Hash[String, Module],
|
27
|
-
)
|
24
|
+
@generic_instances = {} #: Hash[String, Module]
|
28
25
|
|
29
|
-
@type_variables =
|
30
|
-
{}.compare_by_identity,
|
31
|
-
T::Hash[Module, T::Array[TypeVariableModule]],
|
32
|
-
)
|
26
|
+
@type_variables = {}.compare_by_identity #: Hash[Module, Array[TypeVariableModule]]
|
33
27
|
|
34
28
|
class GenericType < T::Types::Simple
|
35
29
|
extend T::Sig
|
36
30
|
|
37
|
-
|
31
|
+
#: (Module raw_type, Module underlying_type) -> void
|
38
32
|
def initialize(raw_type, underlying_type)
|
39
33
|
super(raw_type)
|
40
34
|
|
41
|
-
@underlying_type =
|
35
|
+
@underlying_type = underlying_type #: Module
|
42
36
|
end
|
43
37
|
|
44
|
-
|
38
|
+
# @override
|
39
|
+
#: (untyped obj) -> bool
|
45
40
|
def valid?(obj)
|
46
41
|
obj.is_a?(@underlying_type)
|
47
42
|
end
|
@@ -61,7 +56,7 @@ module Tapioca
|
|
61
56
|
# 2 hash lookups (for the other two `Foo[Integer]`s).
|
62
57
|
#
|
63
58
|
# This method returns the created or cached clone of the constant.
|
64
|
-
|
59
|
+
#: (untyped constant, untyped types) -> Module
|
65
60
|
def register_type(constant, types)
|
66
61
|
# Build the name of the instantiated generic type,
|
67
62
|
# something like `"Foo[X, Y, Z]"`
|
@@ -76,12 +71,12 @@ module Tapioca
|
|
76
71
|
@generic_instances[name] ||= create_generic_type(constant, name)
|
77
72
|
end
|
78
73
|
|
79
|
-
|
74
|
+
#: (Object instance) -> bool
|
80
75
|
def generic_type_instance?(instance)
|
81
76
|
@generic_instances.values.any? { |generic_type| generic_type === instance }
|
82
77
|
end
|
83
78
|
|
84
|
-
|
79
|
+
#: (Module constant) -> Array[TypeVariableModule]?
|
85
80
|
def lookup_type_variables(constant)
|
86
81
|
@type_variables[constant]
|
87
82
|
end
|
@@ -95,12 +90,7 @@ module Tapioca
|
|
95
90
|
#
|
96
91
|
# Finally, the original `type_variable` is returned from this method, so that the caller
|
97
92
|
# can return it from the original methods as well.
|
98
|
-
|
99
|
-
params(
|
100
|
-
constant: T.untyped,
|
101
|
-
type_variable: TypeVariableModule,
|
102
|
-
).void
|
103
|
-
end
|
93
|
+
#: (untyped constant, TypeVariableModule type_variable) -> void
|
104
94
|
def register_type_variable(constant, type_variable)
|
105
95
|
type_variables = lookup_or_initialize_type_variables(constant)
|
106
96
|
|
@@ -109,7 +99,7 @@ module Tapioca
|
|
109
99
|
|
110
100
|
private
|
111
101
|
|
112
|
-
|
102
|
+
#: (Module constant, String name) -> Module
|
113
103
|
def create_generic_type(constant, name)
|
114
104
|
generic_type = case constant
|
115
105
|
when Class
|
@@ -151,7 +141,7 @@ module Tapioca
|
|
151
141
|
generic_type
|
152
142
|
end
|
153
143
|
|
154
|
-
|
144
|
+
#: (Class[top] constant) -> Class[top]
|
155
145
|
def create_safe_subclass(constant)
|
156
146
|
# Lookup the "inherited" class method
|
157
147
|
inherited_method = constant.method(:inherited)
|
@@ -178,7 +168,7 @@ module Tapioca
|
|
178
168
|
end
|
179
169
|
end
|
180
170
|
|
181
|
-
|
171
|
+
#: (Module constant) -> Array[TypeVariableModule]
|
182
172
|
def lookup_or_initialize_type_variables(constant)
|
183
173
|
@type_variables[constant] ||= []
|
184
174
|
end
|
@@ -18,97 +18,93 @@ module Tapioca
|
|
18
18
|
extend T::Sig
|
19
19
|
extend self
|
20
20
|
|
21
|
-
CLASS_METHOD =
|
22
|
-
CONSTANTS_METHOD =
|
23
|
-
NAME_METHOD =
|
24
|
-
SINGLETON_CLASS_METHOD =
|
25
|
-
ANCESTORS_METHOD =
|
26
|
-
SUPERCLASS_METHOD =
|
27
|
-
OBJECT_ID_METHOD =
|
28
|
-
EQUAL_METHOD =
|
29
|
-
PUBLIC_INSTANCE_METHODS_METHOD =
|
30
|
-
PROTECTED_INSTANCE_METHODS_METHOD =
|
31
|
-
PRIVATE_INSTANCE_METHODS_METHOD =
|
32
|
-
METHOD_METHOD =
|
33
|
-
UNDEFINED_CONSTANT =
|
34
|
-
|
35
|
-
REQUIRED_FROM_LABELS =
|
36
|
-
|
37
|
-
|
21
|
+
CLASS_METHOD = Kernel.instance_method(:class) #: UnboundMethod
|
22
|
+
CONSTANTS_METHOD = Module.instance_method(:constants) #: UnboundMethod
|
23
|
+
NAME_METHOD = Module.instance_method(:name) #: UnboundMethod
|
24
|
+
SINGLETON_CLASS_METHOD = Object.instance_method(:singleton_class) #: UnboundMethod
|
25
|
+
ANCESTORS_METHOD = Module.instance_method(:ancestors) #: UnboundMethod
|
26
|
+
SUPERCLASS_METHOD = Class.instance_method(:superclass) #: UnboundMethod
|
27
|
+
OBJECT_ID_METHOD = BasicObject.instance_method(:__id__) #: UnboundMethod
|
28
|
+
EQUAL_METHOD = BasicObject.instance_method(:equal?) #: UnboundMethod
|
29
|
+
PUBLIC_INSTANCE_METHODS_METHOD = Module.instance_method(:public_instance_methods) #: UnboundMethod
|
30
|
+
PROTECTED_INSTANCE_METHODS_METHOD = Module.instance_method(:protected_instance_methods) #: UnboundMethod
|
31
|
+
PRIVATE_INSTANCE_METHODS_METHOD = Module.instance_method(:private_instance_methods) #: UnboundMethod
|
32
|
+
METHOD_METHOD = Kernel.instance_method(:method) #: UnboundMethod
|
33
|
+
UNDEFINED_CONSTANT = Module.new.freeze #: Module
|
34
|
+
|
35
|
+
REQUIRED_FROM_LABELS = ["<top (required)>", "<main>", "<compiled>"].freeze #: Array[String]
|
36
|
+
|
37
|
+
# @without_runtime
|
38
|
+
#: (BasicObject constant) -> bool
|
38
39
|
def constant_defined?(constant)
|
39
40
|
!UNDEFINED_CONSTANT.eql?(constant)
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
symbol: String,
|
45
|
-
inherit: T::Boolean,
|
46
|
-
namespace: Module,
|
47
|
-
).returns(BasicObject).checked(:never)
|
48
|
-
end
|
43
|
+
# @without_runtime
|
44
|
+
#: (String symbol, ?inherit: bool, ?namespace: Module) -> BasicObject
|
49
45
|
def constantize(symbol, inherit: false, namespace: Object)
|
50
46
|
namespace.const_get(symbol, inherit)
|
51
47
|
rescue NameError, LoadError, RuntimeError, ArgumentError, TypeError
|
52
48
|
UNDEFINED_CONSTANT
|
53
49
|
end
|
54
50
|
|
55
|
-
|
51
|
+
#: (BasicObject object) -> Class[top]
|
56
52
|
def class_of(object)
|
57
53
|
CLASS_METHOD.bind_call(object)
|
58
54
|
end
|
59
55
|
|
60
|
-
|
56
|
+
#: (Module constant) -> Array[Symbol]
|
61
57
|
def constants_of(constant)
|
62
58
|
CONSTANTS_METHOD.bind_call(constant, false)
|
63
59
|
end
|
64
60
|
|
65
|
-
|
61
|
+
#: (Module constant) -> String?
|
66
62
|
def name_of(constant)
|
67
63
|
name = NAME_METHOD.bind_call(constant)
|
68
64
|
name&.start_with?("#<") ? nil : name
|
69
65
|
end
|
70
66
|
|
71
|
-
|
67
|
+
#: (Module constant) -> Class[top]
|
72
68
|
def singleton_class_of(constant)
|
73
69
|
SINGLETON_CLASS_METHOD.bind_call(constant)
|
74
70
|
end
|
75
71
|
|
76
|
-
|
72
|
+
#: (Module constant) -> Array[Module]
|
77
73
|
def ancestors_of(constant)
|
78
74
|
ANCESTORS_METHOD.bind_call(constant)
|
79
75
|
end
|
80
76
|
|
81
|
-
|
77
|
+
#: (Class[top] constant) -> Class[top]?
|
82
78
|
def superclass_of(constant)
|
83
79
|
SUPERCLASS_METHOD.bind_call(constant)
|
84
80
|
end
|
85
81
|
|
86
|
-
|
82
|
+
#: (BasicObject object) -> Integer
|
87
83
|
def object_id_of(object)
|
88
84
|
OBJECT_ID_METHOD.bind_call(object)
|
89
85
|
end
|
90
86
|
|
91
|
-
|
87
|
+
#: (BasicObject object, BasicObject other) -> bool
|
92
88
|
def are_equal?(object, other)
|
93
89
|
EQUAL_METHOD.bind_call(object, other)
|
94
90
|
end
|
95
91
|
|
96
|
-
|
92
|
+
#: (Module constant) -> Array[Symbol]
|
97
93
|
def public_instance_methods_of(constant)
|
98
94
|
PUBLIC_INSTANCE_METHODS_METHOD.bind_call(constant)
|
99
95
|
end
|
100
96
|
|
101
|
-
|
97
|
+
#: (Module constant) -> Array[Symbol]
|
102
98
|
def protected_instance_methods_of(constant)
|
103
99
|
PROTECTED_INSTANCE_METHODS_METHOD.bind_call(constant)
|
104
100
|
end
|
105
101
|
|
106
|
-
|
102
|
+
#: (Module constant) -> Array[Symbol]
|
107
103
|
def private_instance_methods_of(constant)
|
108
104
|
PRIVATE_INSTANCE_METHODS_METHOD.bind_call(constant)
|
109
105
|
end
|
110
106
|
|
111
|
-
|
107
|
+
#: (Module constant) -> Array[Module]
|
112
108
|
def inherited_ancestors_of(constant)
|
113
109
|
if Class === constant
|
114
110
|
ancestors_of(superclass_of(constant) || Object)
|
@@ -117,7 +113,7 @@ module Tapioca
|
|
117
113
|
end
|
118
114
|
end
|
119
115
|
|
120
|
-
|
116
|
+
#: (Module constant) -> String?
|
121
117
|
def qualified_name_of(constant)
|
122
118
|
name = name_of(constant)
|
123
119
|
return if name.nil?
|
@@ -129,24 +125,24 @@ module Tapioca
|
|
129
125
|
end
|
130
126
|
end
|
131
127
|
|
132
|
-
|
128
|
+
#: ((UnboundMethod | Method) method) -> untyped
|
133
129
|
def signature_of!(method)
|
134
130
|
T::Utils.signature_for_method(method)
|
135
131
|
end
|
136
132
|
|
137
|
-
|
133
|
+
#: ((UnboundMethod | Method) method) -> untyped
|
138
134
|
def signature_of(method)
|
139
135
|
signature_of!(method)
|
140
136
|
rescue LoadError, StandardError
|
141
137
|
nil
|
142
138
|
end
|
143
139
|
|
144
|
-
|
140
|
+
#: (T::Types::Base type) -> String
|
145
141
|
def name_of_type(type)
|
146
142
|
type.to_s
|
147
143
|
end
|
148
144
|
|
149
|
-
|
145
|
+
#: (Module constant, Symbol method) -> Method
|
150
146
|
def method_of(constant, method)
|
151
147
|
METHOD_METHOD.bind_call(constant, method)
|
152
148
|
end
|
@@ -164,11 +160,7 @@ module Tapioca
|
|
164
160
|
#
|
165
161
|
# class D < C; end
|
166
162
|
# descendants_of(C) # => [B, A, D]
|
167
|
-
|
168
|
-
type_parameters(:U)
|
169
|
-
.params(klass: T.all(T::Class[T.anything], T.type_parameter(:U)))
|
170
|
-
.returns(T::Array[T.type_parameter(:U)])
|
171
|
-
end
|
163
|
+
#: [U] ((Class[top] & U) klass) -> Array[U]
|
172
164
|
def descendants_of(klass)
|
173
165
|
result = ObjectSpace.each_object(klass.singleton_class).reject do |k|
|
174
166
|
k.singleton_class? || k == klass
|
@@ -181,7 +173,7 @@ module Tapioca
|
|
181
173
|
# by searching for the label "<top (required)>" or "block in <class:...>" in the
|
182
174
|
# case of an ActiveSupport.on_load hook. If none is found, it returns the location
|
183
175
|
# labeled "<main>", which is the original call site.
|
184
|
-
|
176
|
+
#: (Array[Thread::Backtrace::Location]? locations) -> String
|
185
177
|
def resolve_loc(locations)
|
186
178
|
return "" unless locations
|
187
179
|
|
@@ -196,32 +188,32 @@ module Tapioca
|
|
196
188
|
resolved_loc.absolute_path || ""
|
197
189
|
end
|
198
190
|
|
199
|
-
|
191
|
+
#: (Module constant) -> Set[String]
|
200
192
|
def file_candidates_for(constant)
|
201
193
|
relevant_methods_for(constant).filter_map do |method|
|
202
194
|
method.source_location&.first
|
203
195
|
end.to_set
|
204
196
|
end
|
205
197
|
|
206
|
-
|
198
|
+
#: (Module constant) -> untyped
|
207
199
|
def abstract_type_of(constant)
|
208
200
|
T::Private::Abstract::Data.get(constant, :abstract_type) ||
|
209
201
|
T::Private::Abstract::Data.get(singleton_class_of(constant), :abstract_type)
|
210
202
|
end
|
211
203
|
|
212
|
-
|
204
|
+
#: (Module constant) -> bool
|
213
205
|
def final_module?(constant)
|
214
206
|
T::Private::Final.final_module?(constant)
|
215
207
|
end
|
216
208
|
|
217
|
-
|
209
|
+
#: (Module constant) -> bool
|
218
210
|
def sealed_module?(constant)
|
219
211
|
T::Private::Sealed.sealed_module?(constant)
|
220
212
|
end
|
221
213
|
|
222
214
|
private
|
223
215
|
|
224
|
-
|
216
|
+
#: (Module constant) -> Array[UnboundMethod]
|
225
217
|
def relevant_methods_for(constant)
|
226
218
|
methods = methods_for(constant).select(&:source_location)
|
227
219
|
.reject { |x| method_defined_by_forwardable_module?(x) }
|
@@ -237,7 +229,7 @@ module Tapioca
|
|
237
229
|
end
|
238
230
|
end
|
239
231
|
|
240
|
-
|
232
|
+
#: (Module constant) -> Array[UnboundMethod]
|
241
233
|
def methods_for(constant)
|
242
234
|
modules = [constant, singleton_class_of(constant)]
|
243
235
|
method_list_methods = [
|
@@ -251,7 +243,7 @@ module Tapioca
|
|
251
243
|
end
|
252
244
|
end
|
253
245
|
|
254
|
-
|
246
|
+
#: (Module parent, String name) -> Module?
|
255
247
|
def child_module_for_parent_with_name(parent, name)
|
256
248
|
return if parent.autoload?(name)
|
257
249
|
|
@@ -262,12 +254,12 @@ module Tapioca
|
|
262
254
|
child
|
263
255
|
end
|
264
256
|
|
265
|
-
|
257
|
+
#: (UnboundMethod method) -> bool
|
266
258
|
def method_defined_by_forwardable_module?(method)
|
267
259
|
method.source_location&.first == Object.const_source_location(:Forwardable)&.first
|
268
260
|
end
|
269
261
|
|
270
|
-
|
262
|
+
#: (String name) -> bool
|
271
263
|
def has_aliased_namespace?(name)
|
272
264
|
name_parts = name.split("::")
|
273
265
|
name_parts.pop # drop the constant name, leaving just the namespace
|
@@ -10,12 +10,12 @@ module Tapioca
|
|
10
10
|
|
11
11
|
NOOP_METHOD = ->(*_args, **_kwargs, &_block) {}
|
12
12
|
|
13
|
-
@constant_names_registered_for_autoload =
|
13
|
+
@constant_names_registered_for_autoload = [] #: Array[String]
|
14
14
|
|
15
15
|
class << self
|
16
16
|
extend T::Sig
|
17
17
|
|
18
|
-
|
18
|
+
#: -> void
|
19
19
|
def eager_load_all!
|
20
20
|
with_disabled_exits do
|
21
21
|
until @constant_names_registered_for_autoload.empty?
|
@@ -27,18 +27,14 @@ module Tapioca
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
#: (String constant_name) -> void
|
31
31
|
def register(constant_name)
|
32
32
|
return unless enabled?
|
33
33
|
|
34
34
|
@constant_names_registered_for_autoload << constant_name
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
type_parameters(:Result)
|
39
|
-
.params(block: T.proc.returns(T.type_parameter(:Result)))
|
40
|
-
.returns(T.type_parameter(:Result))
|
41
|
-
end
|
37
|
+
#: [Result] { -> Result } -> Result
|
42
38
|
def with_disabled_exits(&block)
|
43
39
|
original_abort = Kernel.instance_method(:abort)
|
44
40
|
original_exit = Kernel.instance_method(:exit)
|
@@ -22,16 +22,12 @@ module Tapioca
|
|
22
22
|
class << self
|
23
23
|
extend T::Sig
|
24
24
|
|
25
|
-
|
26
|
-
type_parameters(:Result)
|
27
|
-
.params(block: T.proc.returns(T.type_parameter(:Result)))
|
28
|
-
.returns(T.type_parameter(:Result))
|
29
|
-
end
|
25
|
+
#: [Result] { -> Result } -> Result
|
30
26
|
def with_disabled_registration(&block)
|
31
27
|
with_disabled_tracker(&block)
|
32
28
|
end
|
33
29
|
|
34
|
-
|
30
|
+
#: (Module constant, Module mixin, Type mixin_type) -> void
|
35
31
|
def register(constant, mixin, mixin_type)
|
36
32
|
return unless enabled?
|
37
33
|
|
@@ -52,19 +48,19 @@ module Tapioca
|
|
52
48
|
attached_class
|
53
49
|
end
|
54
50
|
|
55
|
-
|
51
|
+
#: (Module mixin) -> Hash[Type, Hash[Module, String]]
|
56
52
|
def constants_with_mixin(mixin)
|
57
53
|
find_or_initialize_mixin_lookup(mixin)
|
58
54
|
end
|
59
55
|
|
60
|
-
|
56
|
+
#: (Module mixin, Type mixin_type, Module constant) -> String?
|
61
57
|
def mixin_location(mixin, mixin_type, constant)
|
62
58
|
find_or_initialize_mixin_lookup(mixin).dig(mixin_type, constant)
|
63
59
|
end
|
64
60
|
|
65
61
|
private
|
66
62
|
|
67
|
-
|
63
|
+
#: (Module constant, Module mixin, Type mixin_type, String location) -> void
|
68
64
|
def register_with_location(constant, mixin, mixin_type, location)
|
69
65
|
return unless @enabled
|
70
66
|
|
@@ -72,7 +68,7 @@ module Tapioca
|
|
72
68
|
constants.fetch(mixin_type).store(constant, location)
|
73
69
|
end
|
74
70
|
|
75
|
-
|
71
|
+
#: (Module mixin) -> Hash[Type, Hash[Module, String]]
|
76
72
|
def find_or_initialize_mixin_lookup(mixin)
|
77
73
|
@mixins_to_constants[mixin] ||= {
|
78
74
|
Type::Prepend => {}.compare_by_identity,
|
@@ -11,7 +11,7 @@ module Tapioca
|
|
11
11
|
class << self
|
12
12
|
extend T::Sig
|
13
13
|
|
14
|
-
|
14
|
+
#: (T::Helpers requiring, ^-> void block) -> void
|
15
15
|
def register(requiring, block)
|
16
16
|
return unless enabled?
|
17
17
|
|
@@ -19,12 +19,12 @@ module Tapioca
|
|
19
19
|
ancestors << block
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
#: (Module mod) -> Array[^-> void]
|
23
23
|
def required_ancestors_blocks_by(mod)
|
24
24
|
@required_ancestors_map[mod] || []
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
#: (Module mod) -> Array[untyped]
|
28
28
|
def required_ancestors_by(mod)
|
29
29
|
blocks = required_ancestors_blocks_by(mod)
|
30
30
|
blocks.map do |block|
|
@@ -13,7 +13,7 @@ module Tapioca
|
|
13
13
|
class << self
|
14
14
|
extend T::Sig
|
15
15
|
|
16
|
-
|
16
|
+
#: ((Tracker & Module) base) -> void
|
17
17
|
def extended(base)
|
18
18
|
Trackers.register_tracker(base)
|
19
19
|
base.instance_exec do
|
@@ -22,7 +22,7 @@ module Tapioca
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
#: -> void
|
26
26
|
def disable!
|
27
27
|
@enabled = false
|
28
28
|
end
|
@@ -8,16 +8,12 @@ module Tapioca
|
|
8
8
|
module Trackers
|
9
9
|
extend T::Sig
|
10
10
|
|
11
|
-
@trackers =
|
11
|
+
@trackers = [] #: Array[Tracker]
|
12
12
|
|
13
13
|
class << self
|
14
14
|
extend T::Sig
|
15
15
|
|
16
|
-
|
17
|
-
type_parameters(:Return)
|
18
|
-
.params(blk: T.proc.returns(T.type_parameter(:Return)))
|
19
|
-
.returns(T.type_parameter(:Return))
|
20
|
-
end
|
16
|
+
#: [Return] { -> Return } -> Return
|
21
17
|
def with_trackers_enabled(&blk)
|
22
18
|
# Currently this is a dirty hack to ensure disabling trackers
|
23
19
|
# doesn't work while in the block passed to this method.
|
@@ -30,12 +26,12 @@ module Tapioca
|
|
30
26
|
end
|
31
27
|
end
|
32
28
|
|
33
|
-
|
29
|
+
#: -> void
|
34
30
|
def disable_all!
|
35
31
|
@trackers.each(&:disable!)
|
36
32
|
end
|
37
33
|
|
38
|
-
|
34
|
+
#: (Tracker tracker) -> void
|
39
35
|
def register_tracker(tracker)
|
40
36
|
@trackers << tracker
|
41
37
|
end
|