tapioca 0.17.8 → 0.17.10
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 +2 -2
- data/lib/tapioca/commands/abstract_dsl.rb +21 -2
- data/lib/tapioca/commands/abstract_gem.rb +21 -2
- data/lib/tapioca/commands/annotations.rb +7 -1
- data/lib/tapioca/commands/check_shims.rb +9 -1
- data/lib/tapioca/commands/command.rb +1 -1
- data/lib/tapioca/dsl/compiler.rb +17 -12
- data/lib/tapioca/dsl/compilers/aasm.rb +2 -2
- data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +2 -2
- data/lib/tapioca/dsl/compilers/action_mailer.rb +1 -1
- data/lib/tapioca/dsl/compilers/action_text.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_job.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_model_attributes.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +7 -1
- data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_associations.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_columns.rb +8 -2
- data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_enum.rb +2 -2
- data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_relations.rb +94 -100
- data/lib/tapioca/dsl/compilers/active_record_scope.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_store.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_resource.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_storage.rb +2 -2
- data/lib/tapioca/dsl/compilers/active_support_concern.rb +6 -6
- data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +1 -1
- data/lib/tapioca/dsl/compilers/config.rb +2 -2
- data/lib/tapioca/dsl/compilers/frozen_record.rb +1 -1
- data/lib/tapioca/dsl/compilers/graphql_input_object.rb +1 -1
- data/lib/tapioca/dsl/compilers/graphql_mutation.rb +1 -1
- data/lib/tapioca/dsl/compilers/identity_cache.rb +2 -2
- data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +1 -1
- data/lib/tapioca/dsl/compilers/kredis.rb +1 -1
- data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +2 -2
- data/lib/tapioca/dsl/compilers/protobuf.rb +7 -3
- data/lib/tapioca/dsl/compilers/rails_generators.rb +1 -1
- data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +1 -1
- data/lib/tapioca/dsl/compilers/smart_properties.rb +1 -1
- data/lib/tapioca/dsl/compilers/state_machines.rb +2 -2
- data/lib/tapioca/dsl/compilers/url_helpers.rb +7 -7
- data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +7 -3
- data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +18 -3
- data/lib/tapioca/dsl/pipeline.rb +25 -11
- data/lib/tapioca/gem/events.rb +15 -8
- data/lib/tapioca/gem/listeners/methods.rb +19 -7
- data/lib/tapioca/gem/listeners/mixins.rb +3 -3
- data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +1 -1
- data/lib/tapioca/gem/pipeline.rb +25 -18
- data/lib/tapioca/gemfile.rb +1 -1
- data/lib/tapioca/helpers/config_helper.rb +5 -1
- data/lib/tapioca/helpers/rbi_files_helper.rb +8 -1
- data/lib/tapioca/helpers/test/content.rb +1 -1
- data/lib/tapioca/internal.rb +1 -0
- data/lib/tapioca/loaders/gem.rb +15 -3
- data/lib/tapioca/rbi_ext/model.rb +9 -2
- data/lib/tapioca/repo_index.rb +1 -1
- 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 +6 -6
- data/lib/tapioca/runtime/generic_type_registry.rb +8 -8
- data/lib/tapioca/runtime/helpers.rb +40 -0
- data/lib/tapioca/runtime/reflection.rb +19 -19
- data/lib/tapioca/runtime/trackers/autoload.rb +1 -1
- data/lib/tapioca/runtime/trackers/constant_definition.rb +3 -3
- data/lib/tapioca/runtime/trackers/method_definition.rb +4 -4
- data/lib/tapioca/runtime/trackers/mixin.rb +5 -5
- data/lib/tapioca/runtime/trackers/required_ancestor.rb +3 -3
- data/lib/tapioca/runtime/trackers/tracker.rb +1 -1
- data/lib/tapioca/sorbet_ext/generic_name_patch.rb +4 -4
- data/lib/tapioca/sorbet_ext/name_patch.rb +3 -14
- data/lib/tapioca/static/requires_compiler.rb +1 -1
- data/lib/tapioca/version.rb +1 -1
- data/lib/tapioca.rb +0 -36
- metadata +20 -19
|
@@ -24,7 +24,13 @@ module Tapioca
|
|
|
24
24
|
compile_directly_owned_methods(node, symbol, singleton_class_of(constant), attached_class: constant)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
#: (
|
|
27
|
+
#: (
|
|
28
|
+
#| RBI::Tree tree,
|
|
29
|
+
#| String module_name,
|
|
30
|
+
#| T::Module[top] mod,
|
|
31
|
+
#| ?Array[Symbol] for_visibility,
|
|
32
|
+
#| ?attached_class: T::Module[top]?
|
|
33
|
+
#| ) -> void
|
|
28
34
|
def compile_directly_owned_methods(
|
|
29
35
|
tree,
|
|
30
36
|
module_name,
|
|
@@ -52,7 +58,13 @@ module Tapioca
|
|
|
52
58
|
end
|
|
53
59
|
end
|
|
54
60
|
|
|
55
|
-
#: (
|
|
61
|
+
#: (
|
|
62
|
+
#| RBI::Tree tree,
|
|
63
|
+
#| String symbol_name,
|
|
64
|
+
#| T::Module[top] constant,
|
|
65
|
+
#| UnboundMethod? method,
|
|
66
|
+
#| ?RBI::Visibility visibility
|
|
67
|
+
#| ) -> void
|
|
56
68
|
def compile_method(tree, symbol_name, constant, method, visibility = RBI::Public.new)
|
|
57
69
|
return unless method
|
|
58
70
|
return unless method_owned_by_constant?(method, constant)
|
|
@@ -159,7 +171,7 @@ module Tapioca
|
|
|
159
171
|
# This method implements a better way of checking whether a constant defines a method.
|
|
160
172
|
# It walks up the ancestor tree via the `super_method` method; if any of the super
|
|
161
173
|
# methods are owned by the constant, it means that the constant declares the method.
|
|
162
|
-
#: (UnboundMethod method, Module constant) -> bool
|
|
174
|
+
#: (UnboundMethod method, T::Module[top] constant) -> bool
|
|
163
175
|
def method_owned_by_constant?(method, constant)
|
|
164
176
|
# Widen the type of `method` to be nilable
|
|
165
177
|
method = method #: UnboundMethod?
|
|
@@ -173,7 +185,7 @@ module Tapioca
|
|
|
173
185
|
false
|
|
174
186
|
end
|
|
175
187
|
|
|
176
|
-
#: (Module mod) -> Hash[Symbol, Array[Symbol]]
|
|
188
|
+
#: (T::Module[top] mod) -> Hash[Symbol, Array[Symbol]]
|
|
177
189
|
def method_names_by_visibility(mod)
|
|
178
190
|
{
|
|
179
191
|
public: public_instance_methods_of(mod),
|
|
@@ -182,7 +194,7 @@ module Tapioca
|
|
|
182
194
|
}
|
|
183
195
|
end
|
|
184
196
|
|
|
185
|
-
#: (Module constant, String method_name) -> bool
|
|
197
|
+
#: (T::Module[top] constant, String method_name) -> bool
|
|
186
198
|
def struct_method?(constant, method_name)
|
|
187
199
|
return false unless T::Props::ClassMethods === constant
|
|
188
200
|
|
|
@@ -192,7 +204,7 @@ module Tapioca
|
|
|
192
204
|
.include?(method_name.gsub(/=$/, "").to_sym)
|
|
193
205
|
end
|
|
194
206
|
|
|
195
|
-
#: (Module? attached_class, Symbol method_name) -> bool?
|
|
207
|
+
#: (T::Module[top]? attached_class, Symbol method_name) -> bool?
|
|
196
208
|
def method_new_in_abstract_class?(attached_class, method_name)
|
|
197
209
|
attached_class &&
|
|
198
210
|
method_name == :new &&
|
|
@@ -200,7 +212,7 @@ module Tapioca
|
|
|
200
212
|
Class === attached_class.singleton_class
|
|
201
213
|
end
|
|
202
214
|
|
|
203
|
-
#: (Module constant) -> UnboundMethod?
|
|
215
|
+
#: (T::Module[top] constant) -> UnboundMethod?
|
|
204
216
|
def initialize_method_for(constant)
|
|
205
217
|
constant.instance_method(:initialize)
|
|
206
218
|
rescue
|
|
@@ -32,7 +32,7 @@ module Tapioca
|
|
|
32
32
|
add_mixins(node, constant, extends.reverse, Runtime::Trackers::Mixin::Type::Extend)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
#: (RBI::Tree tree, Module constant, Array[Module] mods, Runtime::Trackers::Mixin::Type mixin_type) -> void
|
|
35
|
+
#: (RBI::Tree tree, T::Module[top] constant, Array[T::Module[top]] mods, Runtime::Trackers::Mixin::Type mixin_type) -> void
|
|
36
36
|
def add_mixins(tree, constant, mods, mixin_type)
|
|
37
37
|
mods
|
|
38
38
|
.select do |mod|
|
|
@@ -59,7 +59,7 @@ module Tapioca
|
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
#: (Module constant, Module mixin, Runtime::Trackers::Mixin::Type mixin_type) -> bool
|
|
62
|
+
#: (T::Module[top] constant, T::Module[top] mixin, Runtime::Trackers::Mixin::Type mixin_type) -> bool
|
|
63
63
|
def mixed_in_by_gem?(constant, mixin, mixin_type)
|
|
64
64
|
mixin_location = Runtime::Trackers::Mixin.mixin_location(mixin, mixin_type, constant)
|
|
65
65
|
|
|
@@ -75,7 +75,7 @@ module Tapioca
|
|
|
75
75
|
mixin_name.start_with?("T::") && !mixin_name.start_with?("T::Props")
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
#: (Module constant) -> Array[Module]
|
|
78
|
+
#: (T::Module[top] constant) -> Array[T::Module[top]]
|
|
79
79
|
def interesting_ancestors_of(constant)
|
|
80
80
|
inherited_ancestors = Set.new.compare_by_identity.merge(inherited_ancestors_of(constant))
|
|
81
81
|
|
|
@@ -24,7 +24,7 @@ module Tapioca
|
|
|
24
24
|
node << sclass if sclass.nodes.length > 1
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
#: (RBI::Tree tree, Module constant) -> void
|
|
27
|
+
#: (RBI::Tree tree, T::Module[top] constant) -> void
|
|
28
28
|
def compile_type_variable_declarations(tree, constant)
|
|
29
29
|
# Try to find the type variables defined on this constant, bail if we can't
|
|
30
30
|
type_variables = Runtime::GenericTypeRegistry.lookup_type_variables(constant)
|
data/lib/tapioca/gem/pipeline.rb
CHANGED
|
@@ -72,27 +72,34 @@ module Tapioca
|
|
|
72
72
|
@events << Gem::ConstantFound.new(symbol, constant)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
#: (String symbol, Module constant) -> void
|
|
75
|
+
#: (String symbol, T::Module[top] constant) -> void
|
|
76
76
|
def push_foreign_constant(symbol, constant)
|
|
77
77
|
@events << Gem::ForeignConstantFound.new(symbol, constant)
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
#: (String symbol, Module constant, RBI::Const node) -> void
|
|
80
|
+
#: (String symbol, T::Module[top] constant, RBI::Const node) -> void
|
|
81
81
|
def push_const(symbol, constant, node)
|
|
82
82
|
@events << Gem::ConstNodeAdded.new(symbol, constant, node)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
#: (String symbol, Module constant, RBI::Scope node) -> void
|
|
85
|
+
#: (String symbol, T::Module[top] constant, RBI::Scope node) -> void
|
|
86
86
|
def push_scope(symbol, constant, node)
|
|
87
87
|
@events << Gem::ScopeNodeAdded.new(symbol, constant, node)
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
#: (String symbol, Module constant, RBI::Scope node) -> void
|
|
90
|
+
#: (String symbol, T::Module[top] constant, RBI::Scope node) -> void
|
|
91
91
|
def push_foreign_scope(symbol, constant, node)
|
|
92
92
|
@events << Gem::ForeignScopeNodeAdded.new(symbol, constant, node)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
#: (
|
|
95
|
+
#: (
|
|
96
|
+
#| String symbol,
|
|
97
|
+
#| T::Module[top] constant,
|
|
98
|
+
#| UnboundMethod method,
|
|
99
|
+
#| RBI::Method node,
|
|
100
|
+
#| untyped signature,
|
|
101
|
+
#| Array[[Symbol, String]] parameters
|
|
102
|
+
#| ) -> void
|
|
96
103
|
def push_method(symbol, constant, method, node, signature, parameters) # rubocop:disable Metrics/ParameterLists
|
|
97
104
|
@events << Gem::MethodNodeAdded.new(symbol, constant, method, node, signature, parameters)
|
|
98
105
|
end
|
|
@@ -145,7 +152,7 @@ module Tapioca
|
|
|
145
152
|
end
|
|
146
153
|
end
|
|
147
154
|
|
|
148
|
-
#: (Symbol method_name, Module owner) -> MethodDefinitionLookupResult
|
|
155
|
+
#: (Symbol method_name, T::Module[top] owner) -> MethodDefinitionLookupResult
|
|
149
156
|
def method_definition_in_gem(method_name, owner)
|
|
150
157
|
definitions = Tapioca::Runtime::Trackers::MethodDefinition.method_definitions_for(method_name, owner)
|
|
151
158
|
|
|
@@ -171,7 +178,7 @@ module Tapioca
|
|
|
171
178
|
|
|
172
179
|
# Helpers
|
|
173
180
|
|
|
174
|
-
#: (Module constant) -> String?
|
|
181
|
+
#: (T::Module[top] constant) -> String?
|
|
175
182
|
def name_of(constant)
|
|
176
183
|
name = name_of_proxy_target(constant, super(class_of(constant)))
|
|
177
184
|
return name if name
|
|
@@ -243,7 +250,7 @@ module Tapioca
|
|
|
243
250
|
|
|
244
251
|
# Compiling
|
|
245
252
|
|
|
246
|
-
#: (String symbol, Module constant) -> void
|
|
253
|
+
#: (String symbol, T::Module[top] constant) -> void
|
|
247
254
|
def compile_foreign_constant(symbol, constant)
|
|
248
255
|
return if skip_foreign_constant?(symbol, constant)
|
|
249
256
|
return if seen?(symbol)
|
|
@@ -269,7 +276,7 @@ module Tapioca
|
|
|
269
276
|
end
|
|
270
277
|
end
|
|
271
278
|
|
|
272
|
-
#: (String name, Module constant) -> void
|
|
279
|
+
#: (String name, T::Module[top] constant) -> void
|
|
273
280
|
def compile_alias(name, constant)
|
|
274
281
|
return if seen?(name)
|
|
275
282
|
|
|
@@ -324,7 +331,7 @@ module Tapioca
|
|
|
324
331
|
@root << node
|
|
325
332
|
end
|
|
326
333
|
|
|
327
|
-
#: (String name, Module constant) -> void
|
|
334
|
+
#: (String name, T::Module[top] constant) -> void
|
|
328
335
|
def compile_module(name, constant)
|
|
329
336
|
return if skip_module?(name, constant)
|
|
330
337
|
return if seen?(name)
|
|
@@ -335,7 +342,7 @@ module Tapioca
|
|
|
335
342
|
push_scope(name, constant, scope)
|
|
336
343
|
end
|
|
337
344
|
|
|
338
|
-
#: (String name, Module constant) -> RBI::Scope
|
|
345
|
+
#: (String name, T::Module[top] constant) -> RBI::Scope
|
|
339
346
|
def compile_scope(name, constant)
|
|
340
347
|
scope = if constant.is_a?(Class)
|
|
341
348
|
superclass = compile_superclass(constant)
|
|
@@ -418,7 +425,7 @@ module Tapioca
|
|
|
418
425
|
false
|
|
419
426
|
end
|
|
420
427
|
|
|
421
|
-
#: (String name, Module constant) -> bool
|
|
428
|
+
#: (String name, T::Module[top] constant) -> bool
|
|
422
429
|
def skip_alias?(name, constant)
|
|
423
430
|
return true if symbol_in_payload?(name)
|
|
424
431
|
return true unless constant_in_gem?(name)
|
|
@@ -436,12 +443,12 @@ module Tapioca
|
|
|
436
443
|
false
|
|
437
444
|
end
|
|
438
445
|
|
|
439
|
-
#: (String name, Module constant) -> bool
|
|
446
|
+
#: (String name, T::Module[top] constant) -> bool
|
|
440
447
|
def skip_foreign_constant?(name, constant)
|
|
441
448
|
Tapioca::TypeVariableModule === constant
|
|
442
449
|
end
|
|
443
450
|
|
|
444
|
-
#: (String name, Module constant) -> bool
|
|
451
|
+
#: (String name, T::Module[top] constant) -> bool
|
|
445
452
|
def skip_module?(name, constant)
|
|
446
453
|
return true unless defined_in_gem?(constant, strict: false)
|
|
447
454
|
return true if Tapioca::TypeVariableModule === constant
|
|
@@ -449,7 +456,7 @@ module Tapioca
|
|
|
449
456
|
false
|
|
450
457
|
end
|
|
451
458
|
|
|
452
|
-
#: (Module constant, ?strict: bool) -> bool
|
|
459
|
+
#: (T::Module[top] constant, ?strict: bool) -> bool
|
|
453
460
|
def defined_in_gem?(constant, strict: true)
|
|
454
461
|
files = get_file_candidates(constant)
|
|
455
462
|
.merge(Runtime::Trackers::ConstantDefinition.files_for(constant))
|
|
@@ -461,7 +468,7 @@ module Tapioca
|
|
|
461
468
|
end
|
|
462
469
|
end
|
|
463
470
|
|
|
464
|
-
#: (Module constant) -> Set[String]
|
|
471
|
+
#: (T::Module[top] constant) -> Set[String]
|
|
465
472
|
def get_file_candidates(constant)
|
|
466
473
|
file_candidates_for(constant)
|
|
467
474
|
rescue ArgumentError, NameError
|
|
@@ -492,7 +499,7 @@ module Tapioca
|
|
|
492
499
|
|
|
493
500
|
# Helpers
|
|
494
501
|
|
|
495
|
-
#: ((Module & T::Generic) constant) -> String
|
|
502
|
+
#: ((T::Module[top] & T::Generic) constant) -> String
|
|
496
503
|
def generic_name_of(constant)
|
|
497
504
|
type_name = T.must(constant.name)
|
|
498
505
|
return type_name if type_name =~ /\[.*\]$/
|
|
@@ -508,7 +515,7 @@ module Tapioca
|
|
|
508
515
|
"#{type_name}[#{type_variable_names}]"
|
|
509
516
|
end
|
|
510
517
|
|
|
511
|
-
#: (Module constant, String? class_name) -> String?
|
|
518
|
+
#: (T::Module[top] constant, String? class_name) -> String?
|
|
512
519
|
def name_of_proxy_target(constant, class_name)
|
|
513
520
|
return unless class_name == "ActiveSupport::Deprecation::DeprecatedConstantProxy"
|
|
514
521
|
|
data/lib/tapioca/gemfile.rb
CHANGED
|
@@ -64,7 +64,7 @@ module Tapioca
|
|
|
64
64
|
[dependencies, missing_specs]
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
#: -> [
|
|
67
|
+
#: -> [Enumerable[Spec], Array[String]]
|
|
68
68
|
def materialize_deps
|
|
69
69
|
deps = definition.locked_gems.dependencies.except(*@excluded_gems).values
|
|
70
70
|
resolve = definition.resolve
|
|
@@ -89,7 +89,11 @@ module Tapioca
|
|
|
89
89
|
@validating_config = false
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
#: (
|
|
92
|
+
#: (
|
|
93
|
+
#| Hash[Symbol, Thor::Option] command_options,
|
|
94
|
+
#| String config_key,
|
|
95
|
+
#| Hash[untyped, untyped] config_options
|
|
96
|
+
#| ) -> Array[ConfigError]
|
|
93
97
|
def validate_config_options(command_options, config_key, config_options)
|
|
94
98
|
config_options.filter_map do |config_option_key, config_option_value|
|
|
95
99
|
command_option = command_options[config_option_key.to_sym]
|
|
@@ -64,7 +64,14 @@ module Tapioca
|
|
|
64
64
|
url
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
#: (
|
|
67
|
+
#: (
|
|
68
|
+
#| command: String,
|
|
69
|
+
#| gem_dir: String,
|
|
70
|
+
#| dsl_dir: String,
|
|
71
|
+
#| auto_strictness: bool,
|
|
72
|
+
#| ?gems: Array[Gemfile::GemSpec],
|
|
73
|
+
#| ?compilers: Enumerable[singleton(Dsl::Compiler)]
|
|
74
|
+
#| ) -> void
|
|
68
75
|
def validate_rbi_files(command:, gem_dir:, dsl_dir:, auto_strictness:, gems: [], compilers: [])
|
|
69
76
|
error_url_base = Spoom::Sorbet::Errors::DEFAULT_ERROR_URL_BASE
|
|
70
77
|
|
|
@@ -28,7 +28,7 @@ module Tapioca
|
|
|
28
28
|
#: (String name, String content, ?require_file: bool) -> String
|
|
29
29
|
def add_ruby_file(name, content, require_file: true)
|
|
30
30
|
add_content_file(name, content).tap do |file_name|
|
|
31
|
-
|
|
31
|
+
Runtime.silence_warnings { require(file_name) } if require_file
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
data/lib/tapioca/internal.rb
CHANGED
data/lib/tapioca/loaders/gem.rb
CHANGED
|
@@ -9,7 +9,13 @@ module Tapioca
|
|
|
9
9
|
class << self
|
|
10
10
|
extend T::Sig
|
|
11
11
|
|
|
12
|
-
#: (
|
|
12
|
+
#: (
|
|
13
|
+
#| bundle: Gemfile,
|
|
14
|
+
#| prerequire: String?,
|
|
15
|
+
#| postrequire: String,
|
|
16
|
+
#| default_command: String,
|
|
17
|
+
#| halt_upon_load_error: bool
|
|
18
|
+
#| ) -> void
|
|
13
19
|
def load_application(bundle:, prerequire:, postrequire:, default_command:, halt_upon_load_error:)
|
|
14
20
|
loader = new(
|
|
15
21
|
bundle: bundle,
|
|
@@ -30,7 +36,13 @@ module Tapioca
|
|
|
30
36
|
|
|
31
37
|
protected
|
|
32
38
|
|
|
33
|
-
#: (
|
|
39
|
+
#: (
|
|
40
|
+
#| bundle: Gemfile,
|
|
41
|
+
#| prerequire: String?,
|
|
42
|
+
#| postrequire: String,
|
|
43
|
+
#| default_command: String,
|
|
44
|
+
#| halt_upon_load_error: bool
|
|
45
|
+
#| ) -> void
|
|
34
46
|
def initialize(bundle:, prerequire:, postrequire:, default_command:, halt_upon_load_error:)
|
|
35
47
|
super()
|
|
36
48
|
|
|
@@ -47,7 +59,7 @@ module Tapioca
|
|
|
47
59
|
|
|
48
60
|
bundle_loaded = true #: bool
|
|
49
61
|
|
|
50
|
-
|
|
62
|
+
Runtime.with_disabled_exits do
|
|
51
63
|
load_bundle(@bundle, @prerequire, @postrequire, @halt_upon_load_error)
|
|
52
64
|
rescue LoadError => e
|
|
53
65
|
bundle_loaded = false
|
|
@@ -5,7 +5,7 @@ module RBI
|
|
|
5
5
|
class Tree
|
|
6
6
|
extend T::Sig
|
|
7
7
|
|
|
8
|
-
#: (::Module constant) ?{ (Scope scope) -> void } -> Scope
|
|
8
|
+
#: (T::Module[top] constant) ?{ (Scope scope) -> void } -> Scope
|
|
9
9
|
def create_path(constant, &block)
|
|
10
10
|
constant_name = Tapioca::Runtime::Reflection.name_of(constant)
|
|
11
11
|
raise "given constant does not have a name" unless constant_name
|
|
@@ -61,7 +61,14 @@ module RBI
|
|
|
61
61
|
create_node(RBI::TypeMember.new(name, value))
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
#: (
|
|
64
|
+
#: (
|
|
65
|
+
#| String name,
|
|
66
|
+
#| ?parameters: Array[TypedParam],
|
|
67
|
+
#| ?return_type: String?,
|
|
68
|
+
#| ?class_method: bool,
|
|
69
|
+
#| ?visibility: RBI::Visibility,
|
|
70
|
+
#| ?comments: Array[RBI::Comment]
|
|
71
|
+
#| ) ?{ (RBI::Method node) -> void } -> void
|
|
65
72
|
def create_method(name, parameters: [], return_type: nil, class_method: false, visibility: RBI::Public.new,
|
|
66
73
|
comments: [], &block)
|
|
67
74
|
return unless Tapioca::RBIHelper.valid_method_name?(name)
|
data/lib/tapioca/repo_index.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Tapioca
|
|
|
10
10
|
module AttachedClassOf
|
|
11
11
|
extend T::Sig
|
|
12
12
|
|
|
13
|
-
#: (Class singleton_class) -> Module?
|
|
13
|
+
#: (Class singleton_class) -> T::Module[top]?
|
|
14
14
|
def attached_class_of(singleton_class)
|
|
15
15
|
result = singleton_class.attached_object
|
|
16
16
|
Module === result ? result : nil
|
|
@@ -10,7 +10,7 @@ module Tapioca
|
|
|
10
10
|
# @requires_ancestor: Tapioca::Runtime::Reflection
|
|
11
11
|
module AttachedClassOf
|
|
12
12
|
extend T::Sig
|
|
13
|
-
#: (Class singleton_class) -> Module?
|
|
13
|
+
#: (Class singleton_class) -> T::Module[top]?
|
|
14
14
|
def attached_class_of(singleton_class)
|
|
15
15
|
# https://stackoverflow.com/a/36622320/98634
|
|
16
16
|
result = ObjectSpace.each_object(singleton_class).find do |klass|
|
|
@@ -7,7 +7,7 @@ module Tapioca
|
|
|
7
7
|
extend T::Sig
|
|
8
8
|
include Runtime::Reflection
|
|
9
9
|
|
|
10
|
-
#: Array[Module]
|
|
10
|
+
#: Array[T::Module[top]]
|
|
11
11
|
attr_reader :dynamic_extends, :dynamic_includes
|
|
12
12
|
|
|
13
13
|
#: Array[Symbol]
|
|
@@ -16,7 +16,7 @@ module Tapioca
|
|
|
16
16
|
#: Array[Symbol]
|
|
17
17
|
attr_reader :instance_attribute_readers, :instance_attribute_writers, :instance_attribute_predicates
|
|
18
18
|
|
|
19
|
-
#: (Module constant) -> void
|
|
19
|
+
#: (T::Module[top] constant) -> void
|
|
20
20
|
def initialize(constant)
|
|
21
21
|
@constant = constant
|
|
22
22
|
mixins_from_modules = {}.compare_by_identity
|
|
@@ -112,12 +112,12 @@ 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 = mixins_from_modules.delete(constant) || [] #: Array[Module]
|
|
115
|
+
@dynamic_extends = mixins_from_modules.delete(constant) || [] #: Array[T::Module[top]]
|
|
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 = mixins_from_modules.keys #: Array[Module]
|
|
120
|
+
@dynamic_includes = mixins_from_modules.keys #: Array[T::Module[top]]
|
|
121
121
|
|
|
122
122
|
@class_attribute_readers = class_attribute_readers #: Array[Symbol]
|
|
123
123
|
@class_attribute_writers = class_attribute_writers #: Array[Symbol]
|
|
@@ -176,7 +176,7 @@ module Tapioca
|
|
|
176
176
|
tree << RBI::Include.new("GeneratedInstanceMethods")
|
|
177
177
|
end
|
|
178
178
|
|
|
179
|
-
#: (RBI::Tree tree) -> [Array[Module], Array[Module]]
|
|
179
|
+
#: (RBI::Tree tree) -> [Array[T::Module[top]], Array[T::Module[top]]]
|
|
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,7 +211,7 @@ module Tapioca
|
|
|
211
211
|
[[], []] # silence errors
|
|
212
212
|
end
|
|
213
213
|
|
|
214
|
-
#: (Module mod, Array[Module] dynamic_extends) -> bool
|
|
214
|
+
#: (T::Module[top] mod, Array[T::Module[top]] 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)
|
|
@@ -21,18 +21,18 @@ 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 = {} #: Hash[String, Module]
|
|
24
|
+
@generic_instances = {} #: Hash[String, T::Module[top]]
|
|
25
25
|
|
|
26
|
-
@type_variables = {}.compare_by_identity #: Hash[Module, Array[TypeVariableModule]]
|
|
26
|
+
@type_variables = {}.compare_by_identity #: Hash[T::Module[top], Array[TypeVariableModule]]
|
|
27
27
|
|
|
28
28
|
class GenericType < T::Types::Simple
|
|
29
29
|
extend T::Sig
|
|
30
30
|
|
|
31
|
-
#: (Module raw_type, Module underlying_type) -> void
|
|
31
|
+
#: (T::Module[top] raw_type, T::Module[top] underlying_type) -> void
|
|
32
32
|
def initialize(raw_type, underlying_type)
|
|
33
33
|
super(raw_type)
|
|
34
34
|
|
|
35
|
-
@underlying_type = underlying_type #: Module
|
|
35
|
+
@underlying_type = underlying_type #: T::Module[top]
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# @override
|
|
@@ -56,7 +56,7 @@ module Tapioca
|
|
|
56
56
|
# 2 hash lookups (for the other two `Foo[Integer]`s).
|
|
57
57
|
#
|
|
58
58
|
# This method returns the created or cached clone of the constant.
|
|
59
|
-
#: (untyped constant, untyped types) -> Module
|
|
59
|
+
#: (untyped constant, untyped types) -> T::Module[top]
|
|
60
60
|
def register_type(constant, types)
|
|
61
61
|
# Build the name of the instantiated generic type,
|
|
62
62
|
# something like `"Foo[X, Y, Z]"`
|
|
@@ -76,7 +76,7 @@ module Tapioca
|
|
|
76
76
|
@generic_instances.values.any? { |generic_type| generic_type === instance }
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
#: (Module constant) -> Array[TypeVariableModule]?
|
|
79
|
+
#: (T::Module[top] constant) -> Array[TypeVariableModule]?
|
|
80
80
|
def lookup_type_variables(constant)
|
|
81
81
|
@type_variables[constant]
|
|
82
82
|
end
|
|
@@ -99,7 +99,7 @@ module Tapioca
|
|
|
99
99
|
|
|
100
100
|
private
|
|
101
101
|
|
|
102
|
-
#: (Module constant, String name) -> Module
|
|
102
|
+
#: (T::Module[top] constant, String name) -> T::Module[top]
|
|
103
103
|
def create_generic_type(constant, name)
|
|
104
104
|
generic_type = case constant
|
|
105
105
|
when Class
|
|
@@ -168,7 +168,7 @@ module Tapioca
|
|
|
168
168
|
end
|
|
169
169
|
end
|
|
170
170
|
|
|
171
|
-
#: (Module constant) -> Array[TypeVariableModule]
|
|
171
|
+
#: (T::Module[top] constant) -> Array[TypeVariableModule]
|
|
172
172
|
def lookup_or_initialize_type_variables(constant)
|
|
173
173
|
@type_variables[constant] ||= []
|
|
174
174
|
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Tapioca
|
|
5
|
+
module Runtime
|
|
6
|
+
NOOP_METHOD = ->(*_args, **_kwargs, &_block) {} #: ^() -> void
|
|
7
|
+
private_constant :NOOP_METHOD
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
#: [Result] { -> Result } -> Result
|
|
11
|
+
def silence_warnings(&blk)
|
|
12
|
+
original_verbosity = $VERBOSE
|
|
13
|
+
$VERBOSE = nil
|
|
14
|
+
::Gem::DefaultUserInteraction.use_ui(::Gem::SilentUI.new) do
|
|
15
|
+
blk.call
|
|
16
|
+
end
|
|
17
|
+
ensure
|
|
18
|
+
$VERBOSE = original_verbosity
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#: [Result] { -> Result } -> Result
|
|
22
|
+
def with_disabled_exits(&block)
|
|
23
|
+
original_abort = Kernel.instance_method(:abort)
|
|
24
|
+
original_exit = Kernel.instance_method(:exit)
|
|
25
|
+
|
|
26
|
+
begin
|
|
27
|
+
Kernel.define_method(:abort, NOOP_METHOD)
|
|
28
|
+
Kernel.define_method(:exit, NOOP_METHOD)
|
|
29
|
+
|
|
30
|
+
silence_warnings do
|
|
31
|
+
block.call
|
|
32
|
+
end
|
|
33
|
+
ensure
|
|
34
|
+
Kernel.define_method(:exit, original_exit)
|
|
35
|
+
Kernel.define_method(:abort, original_abort)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|