tapioca 0.16.10 → 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.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby_lsp/tapioca/addon.rb +24 -20
  3. data/lib/ruby_lsp/tapioca/run_gem_rbi_check.rb +20 -20
  4. data/lib/tapioca/bundler_ext/auto_require_hook.rb +5 -10
  5. data/lib/tapioca/commands/abstract_dsl.rb +36 -62
  6. data/lib/tapioca/commands/abstract_gem.rb +23 -43
  7. data/lib/tapioca/commands/annotations.rb +27 -33
  8. data/lib/tapioca/commands/check_shims.rb +4 -13
  9. data/lib/tapioca/commands/command.rb +8 -20
  10. data/lib/tapioca/commands/command_without_tracker.rb +1 -1
  11. data/lib/tapioca/commands/configure.rb +11 -16
  12. data/lib/tapioca/commands/dsl_compiler_list.rb +2 -1
  13. data/lib/tapioca/commands/dsl_generate.rb +2 -1
  14. data/lib/tapioca/commands/dsl_verify.rb +2 -1
  15. data/lib/tapioca/commands/gem_generate.rb +4 -8
  16. data/lib/tapioca/commands/gem_sync.rb +2 -1
  17. data/lib/tapioca/commands/gem_verify.rb +3 -2
  18. data/lib/tapioca/commands/require.rb +3 -7
  19. data/lib/tapioca/commands/todo.rb +6 -10
  20. data/lib/tapioca/dsl/compiler.rb +28 -53
  21. data/lib/tapioca/dsl/compilers/aasm.rb +31 -41
  22. data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +7 -5
  23. data/lib/tapioca/dsl/compilers/action_mailer.rb +5 -3
  24. data/lib/tapioca/dsl/compilers/action_text.rb +5 -3
  25. data/lib/tapioca/dsl/compilers/active_job.rb +5 -8
  26. data/lib/tapioca/dsl/compilers/active_model_attributes.rb +9 -7
  27. data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +4 -2
  28. data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +4 -2
  29. data/lib/tapioca/dsl/compilers/active_record_associations.rb +16 -42
  30. data/lib/tapioca/dsl/compilers/active_record_columns.rb +19 -24
  31. data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +7 -5
  32. data/lib/tapioca/dsl/compilers/active_record_enum.rb +6 -4
  33. data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +53 -61
  34. data/lib/tapioca/dsl/compilers/active_record_relations.rb +86 -119
  35. data/lib/tapioca/dsl/compilers/active_record_scope.rb +7 -11
  36. data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +4 -2
  37. data/lib/tapioca/dsl/compilers/active_record_store.rb +4 -2
  38. data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +18 -26
  39. data/lib/tapioca/dsl/compilers/active_resource.rb +18 -19
  40. data/lib/tapioca/dsl/compilers/active_storage.rb +5 -5
  41. data/lib/tapioca/dsl/compilers/active_support_concern.rb +8 -6
  42. data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +7 -5
  43. data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +4 -2
  44. data/lib/tapioca/dsl/compilers/config.rb +4 -2
  45. data/lib/tapioca/dsl/compilers/frozen_record.rb +6 -9
  46. data/lib/tapioca/dsl/compilers/graphql_input_object.rb +8 -8
  47. data/lib/tapioca/dsl/compilers/graphql_mutation.rb +5 -8
  48. data/lib/tapioca/dsl/compilers/identity_cache.rb +10 -37
  49. data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +8 -16
  50. data/lib/tapioca/dsl/compilers/kredis.rb +6 -4
  51. data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +4 -2
  52. data/lib/tapioca/dsl/compilers/protobuf.rb +12 -24
  53. data/lib/tapioca/dsl/compilers/rails_generators.rb +8 -9
  54. data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +22 -11
  55. data/lib/tapioca/dsl/compilers/smart_properties.rb +11 -20
  56. data/lib/tapioca/dsl/compilers/state_machines.rb +14 -24
  57. data/lib/tapioca/dsl/compilers/url_helpers.rb +9 -7
  58. data/lib/tapioca/dsl/compilers.rb +4 -7
  59. data/lib/tapioca/dsl/helpers/active_model_type_helper.rb +13 -16
  60. data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +13 -28
  61. data/lib/tapioca/dsl/helpers/active_record_constants_helper.rb +19 -15
  62. data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +5 -24
  63. data/lib/tapioca/dsl/pipeline.rb +30 -58
  64. data/lib/tapioca/executor.rb +6 -12
  65. data/lib/tapioca/gem/events.rb +22 -28
  66. data/lib/tapioca/gem/listeners/base.rb +6 -6
  67. data/lib/tapioca/gem/listeners/dynamic_mixins.rb +4 -2
  68. data/lib/tapioca/gem/listeners/foreign_constants.rb +5 -7
  69. data/lib/tapioca/gem/listeners/methods.rb +15 -34
  70. data/lib/tapioca/gem/listeners/mixins.rb +6 -18
  71. data/lib/tapioca/gem/listeners/remove_empty_payload_scopes.rb +4 -2
  72. data/lib/tapioca/gem/listeners/sorbet_enums.rb +4 -2
  73. data/lib/tapioca/gem/listeners/sorbet_helpers.rb +4 -2
  74. data/lib/tapioca/gem/listeners/sorbet_props.rb +4 -2
  75. data/lib/tapioca/gem/listeners/sorbet_required_ancestors.rb +4 -2
  76. data/lib/tapioca/gem/listeners/sorbet_signatures.rb +7 -5
  77. data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +6 -4
  78. data/lib/tapioca/gem/listeners/source_location.rb +7 -4
  79. data/lib/tapioca/gem/listeners/subconstants.rb +5 -4
  80. data/lib/tapioca/gem/listeners/yard_doc.rb +23 -22
  81. data/lib/tapioca/gem/pipeline.rb +57 -72
  82. data/lib/tapioca/gem_info.rb +1 -1
  83. data/lib/tapioca/gemfile.rb +64 -73
  84. data/lib/tapioca/helpers/cli_helper.rb +3 -3
  85. data/lib/tapioca/helpers/config_helper.rb +15 -24
  86. data/lib/tapioca/helpers/env_helper.rb +1 -1
  87. data/lib/tapioca/helpers/gem_helper.rb +5 -5
  88. data/lib/tapioca/helpers/git_attributes.rb +3 -3
  89. data/lib/tapioca/helpers/rbi_files_helper.rb +73 -67
  90. data/lib/tapioca/helpers/rbi_helper.rb +14 -22
  91. data/lib/tapioca/helpers/sorbet_helper.rb +9 -18
  92. data/lib/tapioca/helpers/source_uri.rb +15 -25
  93. data/lib/tapioca/helpers/test/content.rb +6 -6
  94. data/lib/tapioca/helpers/test/dsl_compiler.rb +19 -29
  95. data/lib/tapioca/helpers/test/isolation.rb +4 -4
  96. data/lib/tapioca/helpers/test/template.rb +5 -7
  97. data/lib/tapioca/internal.rb +5 -1
  98. data/lib/tapioca/loaders/dsl.rb +11 -19
  99. data/lib/tapioca/loaders/gem.rb +6 -21
  100. data/lib/tapioca/loaders/loader.rb +15 -27
  101. data/lib/tapioca/rbi_ext/model.rb +12 -37
  102. data/lib/tapioca/rbi_formatter.rb +10 -19
  103. data/lib/tapioca/rbs/rewriter.rb +55 -0
  104. data/lib/tapioca/repo_index.rb +7 -7
  105. data/lib/tapioca/runtime/attached_class_of_32.rb +1 -1
  106. data/lib/tapioca/runtime/attached_class_of_legacy.rb +1 -1
  107. data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +23 -23
  108. data/lib/tapioca/runtime/generic_type_registry.rb +13 -23
  109. data/lib/tapioca/runtime/reflection.rb +48 -56
  110. data/lib/tapioca/runtime/trackers/autoload.rb +4 -8
  111. data/lib/tapioca/runtime/trackers/mixin.rb +6 -10
  112. data/lib/tapioca/runtime/trackers/required_ancestor.rb +3 -3
  113. data/lib/tapioca/runtime/trackers/tracker.rb +2 -2
  114. data/lib/tapioca/runtime/trackers.rb +4 -8
  115. data/lib/tapioca/sorbet_ext/generic_name_patch.rb +9 -15
  116. data/lib/tapioca/sorbet_ext/name_patch.rb +1 -1
  117. data/lib/tapioca/sorbet_ext/proc_bind_patch.rb +1 -1
  118. data/lib/tapioca/static/requires_compiler.rb +6 -6
  119. data/lib/tapioca/static/symbol_loader.rb +14 -16
  120. data/lib/tapioca/static/symbol_table_parser.rb +8 -8
  121. data/lib/tapioca/version.rb +1 -1
  122. data/lib/tapioca.rb +22 -29
  123. metadata +25 -10
@@ -9,7 +9,7 @@ module Tapioca
9
9
  class << self
10
10
  extend(T::Sig)
11
11
 
12
- sig { params(spec: Bundler::LazySpecification).returns(GemInfo) }
12
+ #: (Bundler::LazySpecification spec) -> GemInfo
13
13
  def from_spec(spec)
14
14
  new(name: spec.name, version: spec.version)
15
15
  end
@@ -14,34 +14,34 @@ module Tapioca
14
14
  )
15
15
  end
16
16
 
17
- sig { returns(Bundler::Definition) }
17
+ #: Bundler::Definition
18
18
  attr_reader(:definition)
19
19
 
20
- sig { returns(T::Array[GemSpec]) }
20
+ #: Array[GemSpec]
21
21
  attr_reader(:dependencies)
22
22
 
23
- sig { returns(T::Array[String]) }
23
+ #: Array[String]
24
24
  attr_reader(:missing_specs)
25
25
 
26
- sig { params(excluded_gems: T::Array[String]).void }
26
+ #: (Array[String] excluded_gems) -> void
27
27
  def initialize(excluded_gems)
28
- @gemfile = T.let(File.new(Bundler.default_gemfile), File)
29
- @lockfile = T.let(File.new(Bundler.default_lockfile), File)
30
- @definition = T.let(Bundler::Dsl.evaluate(gemfile, lockfile, {}), Bundler::Definition)
28
+ @gemfile = File.new(Bundler.default_gemfile) #: File
29
+ @lockfile = File.new(Bundler.default_lockfile) #: File
30
+ @definition = Bundler::Dsl.evaluate(gemfile, lockfile, {}) #: Bundler::Definition
31
31
  @excluded_gems = excluded_gems
32
32
 
33
33
  dependencies, missing_specs = load_dependencies
34
34
 
35
- @dependencies = T.let(dependencies, T::Array[GemSpec])
36
- @missing_specs = T.let(missing_specs, T::Array[String])
35
+ @dependencies = dependencies #: Array[GemSpec]
36
+ @missing_specs = missing_specs #: Array[String]
37
37
  end
38
38
 
39
- sig { params(gem_name: String).returns(T.nilable(GemSpec)) }
39
+ #: (String gem_name) -> GemSpec?
40
40
  def gem(gem_name)
41
41
  dependencies.detect { |dep| dep.name == gem_name }
42
42
  end
43
43
 
44
- sig { void }
44
+ #: -> void
45
45
  def require_bundle
46
46
  BundlerExt::AutoRequireHook.override_require_false(exclude: @excluded_gems) do
47
47
  T.unsafe(runtime).require(*groups)
@@ -50,10 +50,10 @@ module Tapioca
50
50
 
51
51
  private
52
52
 
53
- sig { returns(File) }
53
+ #: File
54
54
  attr_reader(:gemfile, :lockfile)
55
55
 
56
- sig { returns([T::Array[GemSpec], T::Array[String]]) }
56
+ #: -> [Array[GemSpec], Array[String]]
57
57
  def load_dependencies
58
58
  materialized_dependencies, missing_specs = materialize_deps
59
59
  dependencies = materialized_dependencies
@@ -64,7 +64,7 @@ module Tapioca
64
64
  [dependencies, missing_specs]
65
65
  end
66
66
 
67
- sig { returns([T::Enumerable[Spec], T::Array[String]]) }
67
+ #: -> [T::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
@@ -87,17 +87,17 @@ module Tapioca
87
87
  [materialized_dependencies, missing_specs]
88
88
  end
89
89
 
90
- sig { returns(Bundler::Runtime) }
90
+ #: -> Bundler::Runtime
91
91
  def runtime
92
92
  Bundler::Runtime.new(File.dirname(gemfile.path), definition)
93
93
  end
94
94
 
95
- sig { returns(T::Array[Symbol]) }
95
+ #: -> Array[Symbol]
96
96
  def groups
97
97
  definition.groups
98
98
  end
99
99
 
100
- sig { returns(String) }
100
+ #: -> String
101
101
  def dir
102
102
  File.expand_path(gemfile.path + "/..")
103
103
  end
@@ -109,74 +109,68 @@ module Tapioca
109
109
  class << self
110
110
  extend T::Sig
111
111
 
112
- sig { returns(T::Hash[String, Gemfile::GemSpec]) }
112
+ #: -> Hash[String, Gemfile::GemSpec]
113
113
  def spec_lookup_by_file_path
114
- @lookup ||= T.let(
115
- [*::Gem::Specification.default_stubs, *::Gem::Specification.stubs]
116
- .map! { |spec| new(spec.to_spec) }
117
- .flat_map do |spec|
118
- spec.files.filter_map { |file| [file.realpath.to_s, spec] if file.exist? }
119
- end.to_h,
120
- T.nilable(T::Hash[String, Gemfile::GemSpec]),
121
- )
114
+ @lookup ||= [*::Gem::Specification.default_stubs, *::Gem::Specification.stubs]
115
+ .map! { |spec| new(spec.to_spec) }
116
+ .flat_map do |spec|
117
+ spec.files.filter_map { |file| [file.realpath.to_s, spec] if file.exist? }
118
+ end.to_h #: Hash[String, Gemfile::GemSpec]?
122
119
  end
123
120
  end
124
121
 
125
- IGNORED_GEMS = T.let(
126
- [
127
- "sorbet",
128
- "sorbet-static",
129
- "sorbet-runtime",
130
- "sorbet-static-and-runtime",
131
- "debug",
132
- "irb",
133
- "fakefs",
134
- ].freeze,
135
- T::Array[String],
136
- )
137
-
138
- sig { returns(String) }
122
+ IGNORED_GEMS = [
123
+ "sorbet",
124
+ "sorbet-static",
125
+ "sorbet-runtime",
126
+ "sorbet-static-and-runtime",
127
+ "debug",
128
+ "irb",
129
+ "fakefs",
130
+ ].freeze #: Array[String]
131
+
132
+ #: String
139
133
  attr_reader :full_gem_path, :version
140
134
 
141
- sig { returns(T::Array[Pathname]) }
135
+ #: Array[Pathname]
142
136
  attr_reader :files
143
137
 
144
- sig { params(spec: Spec).void }
138
+ #: (Spec spec) -> void
145
139
  def initialize(spec)
146
- @spec = T.let(spec, Tapioca::Gemfile::Spec)
140
+ @spec = spec #: Tapioca::Gemfile::Spec
147
141
  real_gem_path = to_realpath(@spec.full_gem_path)
148
- @full_gem_path = T.let(real_gem_path, String)
149
- @version = T.let(version_string, String)
150
- @exported_rbi_files = T.let(nil, T.nilable(T::Array[String]))
151
- @files = T.let(collect_files, T::Array[Pathname])
142
+ @full_gem_path = real_gem_path #: String
143
+ @version = version_string #: String
144
+ @exported_rbi_files = nil #: Array[String]?
145
+ @files = collect_files #: Array[Pathname]
152
146
  end
153
147
 
154
- sig { params(other: BasicObject).returns(T::Boolean) }
148
+ #: (BasicObject other) -> bool
155
149
  def ==(other)
156
150
  GemSpec === other && other.name == name && other.version == version
157
151
  end
158
152
 
159
- sig { params(gemfile_dir: String).returns(T::Boolean) }
153
+ #: (String gemfile_dir) -> bool
160
154
  def ignore?(gemfile_dir)
161
155
  gem_ignored? || gem_in_app_dir?(gemfile_dir, full_gem_path)
162
156
  end
163
157
 
164
- sig { returns(String) }
158
+ #: -> String
165
159
  def name
166
160
  @spec.name
167
161
  end
168
162
 
169
- sig { returns(T::Array[::Gem::Dependency]) }
163
+ #: -> Array[::Gem::Dependency]
170
164
  def dependencies
171
165
  @spec.dependencies
172
166
  end
173
167
 
174
- sig { returns(String) }
168
+ #: -> String
175
169
  def rbi_file_name
176
170
  "#{name}@#{version}.rbi"
177
171
  end
178
172
 
179
- sig { params(path: String).returns(T::Boolean) }
173
+ #: (String path) -> bool
180
174
  def contains_path?(path)
181
175
  if default_gem?
182
176
  files.any? { |file| file.to_s == to_realpath(path) }
@@ -185,7 +179,7 @@ module Tapioca
185
179
  end
186
180
  end
187
181
 
188
- sig { void }
182
+ #: -> void
189
183
  def parse_yard_docs
190
184
  files.each do |path|
191
185
  YARD.parse(path.to_s, [], Logger::Severity::FATAL)
@@ -201,17 +195,17 @@ module Tapioca
201
195
  end
202
196
  end
203
197
 
204
- sig { returns(T::Array[String]) }
198
+ #: -> Array[String]
205
199
  def exported_rbi_files
206
200
  @exported_rbi_files ||= Dir.glob("#{full_gem_path}/rbi/**/*.rbi").sort
207
201
  end
208
202
 
209
- sig { returns(T::Boolean) }
203
+ #: -> bool
210
204
  def export_rbi_files?
211
205
  exported_rbi_files.any?
212
206
  end
213
207
 
214
- sig { returns(RBI::MergeTree) }
208
+ #: -> RBI::MergeTree
215
209
  def exported_rbi_tree
216
210
  rewriter = RBI::Rewriters::Merge.new(keep: RBI::Rewriters::Merge::Keep::NONE)
217
211
 
@@ -223,7 +217,7 @@ module Tapioca
223
217
  rewriter.tree
224
218
  end
225
219
 
226
- sig { params(file: Pathname).returns(Pathname) }
220
+ #: (Pathname file) -> Pathname
227
221
  def relative_path_for(file)
228
222
  if default_gem?
229
223
  file.realpath.relative_path_from(RbConfig::CONFIG["rubylibdir"])
@@ -234,7 +228,7 @@ module Tapioca
234
228
 
235
229
  private
236
230
 
237
- sig { returns(T::Array[Pathname]) }
231
+ #: -> Array[Pathname]
238
232
  def collect_files
239
233
  if default_gem?
240
234
  # `Bundler::RemoteSpecification` delegates missing methods to
@@ -249,24 +243,21 @@ module Tapioca
249
243
  end
250
244
  end
251
245
 
252
- sig { returns(T.nilable(T::Boolean)) }
246
+ #: -> bool?
253
247
  def default_gem?
254
248
  @spec.respond_to?(:default_gem?) && @spec.default_gem?
255
249
  end
256
250
 
257
- sig { returns(Regexp) }
251
+ #: -> Regexp
258
252
  def require_paths_prefix_matcher
259
- @require_paths_prefix_matcher ||= T.let(
260
- begin
261
- require_paths = T.unsafe(@spec).require_paths
262
- prefix_matchers = require_paths.map { |rp| Regexp.new("^#{rp}/") }
263
- Regexp.union(prefix_matchers)
264
- end,
265
- T.nilable(Regexp),
266
- )
253
+ @require_paths_prefix_matcher ||= begin
254
+ require_paths = T.unsafe(@spec).require_paths
255
+ prefix_matchers = require_paths.map { |rp| Regexp.new("^#{rp}/") }
256
+ Regexp.union(prefix_matchers)
257
+ end #: Regexp?
267
258
  end
268
259
 
269
- sig { params(file: String).returns(Pathname) }
260
+ #: (String file) -> Pathname
270
261
  def resolve_to_ruby_lib_dir(file)
271
262
  # We want to match require prefixes but fallback to an empty match
272
263
  # if none of the require prefixes actually match. This is so that
@@ -280,14 +271,14 @@ module Tapioca
280
271
  Pathname.new(file).expand_path
281
272
  end
282
273
 
283
- sig { returns(String) }
274
+ #: -> String
284
275
  def version_string
285
276
  version = @spec.version.to_s
286
277
  version += "-#{@spec.source.revision}" if Bundler::Source::Git === @spec.source
287
278
  version
288
279
  end
289
280
 
290
- sig { params(path: String).returns(T::Boolean) }
281
+ #: (String path) -> bool
291
282
  def has_parent_gemspec?(path)
292
283
  # For some Git installed gems the location of the loaded file can
293
284
  # be different from the gem path as indicated by the spec file
@@ -308,7 +299,7 @@ module Tapioca
308
299
  false
309
300
  end
310
301
 
311
- sig { returns(T::Boolean) }
302
+ #: -> bool
312
303
  def gem_ignored?
313
304
  IGNORED_GEMS.include?(name)
314
305
  end
@@ -8,7 +8,7 @@ module Tapioca
8
8
 
9
9
  requires_ancestor { Thor::Shell }
10
10
 
11
- sig { params(message: String, color: T.any(Symbol, T::Array[Symbol])).void }
11
+ #: (?String message, *(Symbol | Array[Symbol]) color) -> void
12
12
  def say_error(message = "", *color)
13
13
  # Thor has its own `say_error` now, but it has two problems:
14
14
  # 1. it adds the padding around all the messages, even if they continue on
@@ -22,14 +22,14 @@ module Tapioca
22
22
  end
23
23
  end
24
24
 
25
- sig { params(options: T::Hash[Symbol, T.untyped]).returns(RBIFormatter) }
25
+ #: (Hash[Symbol, untyped] options) -> RBIFormatter
26
26
  def rbi_formatter(options)
27
27
  rbi_formatter = DEFAULT_RBI_FORMATTER
28
28
  rbi_formatter.max_line_length = options[:rbi_max_line_length]
29
29
  rbi_formatter
30
30
  end
31
31
 
32
- sig { params(options: T::Hash[Symbol, T.untyped]).returns(T.nilable(String)) }
32
+ #: (Hash[Symbol, untyped] options) -> String?
33
33
  def netrc_file(options)
34
34
  return if options[:auth]
35
35
  return unless options[:netrc]
@@ -8,20 +8,20 @@ module Tapioca
8
8
 
9
9
  requires_ancestor { Thor }
10
10
 
11
- sig { returns(String) }
11
+ #: String
12
12
  attr_reader :command_name
13
13
 
14
- sig { returns(Thor::CoreExt::HashWithIndifferentAccess) }
14
+ #: Thor::CoreExt::HashWithIndifferentAccess
15
15
  attr_reader :defaults
16
16
 
17
- sig { params(args: T.untyped, local_options: T.untyped, config: T.untyped).void }
17
+ #: (?untyped args, ?untyped local_options, ?untyped config) -> void
18
18
  def initialize(args = [], local_options = {}, config = {})
19
19
  # Store current command
20
20
  command = config[:current_command]
21
21
  command_options = config[:command_options]
22
- @command_name = T.let(command.name, String)
23
- @merged_options = T.let(nil, T.nilable(Thor::CoreExt::HashWithIndifferentAccess))
24
- @defaults = T.let(Thor::CoreExt::HashWithIndifferentAccess.new, Thor::CoreExt::HashWithIndifferentAccess)
22
+ @command_name = command.name #: String
23
+ @merged_options = nil #: Thor::CoreExt::HashWithIndifferentAccess?
24
+ @defaults = Thor::CoreExt::HashWithIndifferentAccess.new #: Thor::CoreExt::HashWithIndifferentAccess
25
25
 
26
26
  # Filter command options unless we are handling the help command.
27
27
  # This is so that the defaults are printed
@@ -30,7 +30,7 @@ module Tapioca
30
30
  super
31
31
  end
32
32
 
33
- sig { returns(Thor::CoreExt::HashWithIndifferentAccess) }
33
+ #: -> Thor::CoreExt::HashWithIndifferentAccess
34
34
  def options
35
35
  @merged_options ||= begin
36
36
  original_options = super
@@ -42,7 +42,7 @@ module Tapioca
42
42
 
43
43
  private
44
44
 
45
- sig { params(options: T::Hash[Symbol, Thor::Option]).void }
45
+ #: (Hash[Symbol, Thor::Option] options) -> void
46
46
  def filter_defaults(options)
47
47
  options.each do |key, option|
48
48
  # Store the value of the current default in our defaults hash
@@ -52,7 +52,7 @@ module Tapioca
52
52
  end
53
53
  end
54
54
 
55
- sig { params(options: Thor::CoreExt::HashWithIndifferentAccess).returns(Thor::CoreExt::HashWithIndifferentAccess) }
55
+ #: (Thor::CoreExt::HashWithIndifferentAccess options) -> Thor::CoreExt::HashWithIndifferentAccess
56
56
  def config_options(options)
57
57
  config_file = options[:config]
58
58
  config = {}
@@ -66,12 +66,12 @@ module Tapioca
66
66
  Thor::CoreExt::HashWithIndifferentAccess.new(config[command_name] || {})
67
67
  end
68
68
 
69
- sig { params(config_file: String, config: T::Hash[T.untyped, T.untyped]).void }
69
+ #: (String config_file, Hash[untyped, untyped] config) -> void
70
70
  def validate_config!(config_file, config)
71
71
  # To ensure that this is not re-entered, we mark during validation
72
72
  return if @validating_config
73
73
 
74
- @validating_config = T.let(true, T.nilable(T::Boolean))
74
+ @validating_config = true #: bool?
75
75
 
76
76
  commands = T.cast(self, Thor).class.commands
77
77
 
@@ -92,13 +92,7 @@ module Tapioca
92
92
  @validating_config = false
93
93
  end
94
94
 
95
- sig do
96
- params(
97
- command_options: T::Hash[Symbol, Thor::Option],
98
- config_key: String,
99
- config_options: T::Hash[T.untyped, T.untyped],
100
- ).returns(T::Array[ConfigError])
101
- end
95
+ #: (Hash[Symbol, Thor::Option] command_options, String config_key, Hash[untyped, untyped] config_options) -> Array[ConfigError]
102
96
  def validate_config_options(command_options, config_key, config_options)
103
97
  config_options.filter_map do |config_option_key, config_option_value|
104
98
  command_option = command_options[config_option_key.to_sym]
@@ -149,7 +143,7 @@ module Tapioca
149
143
  const :message_parts, T::Array[ConfigErrorMessagePart]
150
144
  end
151
145
 
152
- sig { params(msg: String).returns(ConfigError) }
146
+ #: (String msg) -> ConfigError
153
147
  def build_error(msg)
154
148
  parts = msg.split(/(`[^`]+` ?)/)
155
149
 
@@ -174,7 +168,7 @@ module Tapioca
174
168
  )
175
169
  end
176
170
 
177
- sig { params(config_file: String, errors: T::Array[ConfigError]).returns(String) }
171
+ #: (String config_file, Array[ConfigError] errors) -> String
178
172
  def build_error_message(config_file, errors)
179
173
  error_messages = errors.map do |error|
180
174
  "- " + error.message_parts.map do |part|
@@ -189,10 +183,7 @@ module Tapioca
189
183
  ERROR
190
184
  end
191
185
 
192
- sig do
193
- params(options: T.nilable(Thor::CoreExt::HashWithIndifferentAccess))
194
- .returns(Thor::CoreExt::HashWithIndifferentAccess)
195
- end
186
+ #: (*Thor::CoreExt::HashWithIndifferentAccess? options) -> Thor::CoreExt::HashWithIndifferentAccess
196
187
  def merge_options(*options)
197
188
  merged = options.each_with_object({}) do |option, result|
198
189
  result.merge!(option || {}) do |_, this_val, other_val|
@@ -8,7 +8,7 @@ module Tapioca
8
8
 
9
9
  requires_ancestor { Thor }
10
10
 
11
- sig { params(options: T::Hash[Symbol, T.untyped]).void }
11
+ #: (Hash[Symbol, untyped] options) -> void
12
12
  def set_environment(options) # rubocop:disable Naming/AccessorMethodName
13
13
  ENV["RAILS_ENV"] = ENV["RACK_ENV"] = options[:environment]
14
14
  ENV["RUBY_DEBUG_LAZY"] = "1"
@@ -5,7 +5,7 @@ module Tapioca
5
5
  module GemHelper
6
6
  extend T::Sig
7
7
 
8
- sig { params(app_dir: T.any(String, Pathname), full_gem_path: String).returns(T::Boolean) }
8
+ #: ((String | Pathname) app_dir, String full_gem_path) -> bool
9
9
  def gem_in_app_dir?(app_dir, full_gem_path)
10
10
  app_dir = to_realpath(app_dir)
11
11
  full_gem_path = to_realpath(full_gem_path)
@@ -13,17 +13,17 @@ module Tapioca
13
13
  !gem_in_bundle_path?(full_gem_path) && !gem_in_ruby_path?(full_gem_path) && path_in_dir?(full_gem_path, app_dir)
14
14
  end
15
15
 
16
- sig { params(full_gem_path: String).returns(T::Boolean) }
16
+ #: (String full_gem_path) -> bool
17
17
  def gem_in_bundle_path?(full_gem_path)
18
18
  path_in_dir?(full_gem_path, Bundler.bundle_path) || path_in_dir?(full_gem_path, Bundler.app_cache)
19
19
  end
20
20
 
21
- sig { params(full_gem_path: String).returns(T::Boolean) }
21
+ #: (String full_gem_path) -> bool
22
22
  def gem_in_ruby_path?(full_gem_path)
23
23
  path_in_dir?(full_gem_path, RbConfig::CONFIG["rubylibprefix"])
24
24
  end
25
25
 
26
- sig { params(path: T.any(String, Pathname)).returns(String) }
26
+ #: ((String | Pathname) path) -> String
27
27
  def to_realpath(path)
28
28
  path_string = path.to_s
29
29
  path_string = File.realpath(path_string) if File.exist?(path_string)
@@ -32,7 +32,7 @@ module Tapioca
32
32
 
33
33
  private
34
34
 
35
- sig { params(path: T.any(Pathname, String), dir: T.any(Pathname, String)).returns(T::Boolean) }
35
+ #: ((Pathname | String) path, (Pathname | String) dir) -> bool
36
36
  def path_in_dir?(path, dir)
37
37
  dir = Pathname.new(dir)
38
38
  path = Pathname.new(path)
@@ -5,14 +5,14 @@ class GitAttributes
5
5
  class << self
6
6
  extend T::Sig
7
7
 
8
- sig { params(path: Pathname).void }
8
+ #: (Pathname path) -> void
9
9
  def create_generated_attribute_file(path)
10
10
  create_gitattributes_file(path, <<~CONTENT)
11
11
  **/*.rbi linguist-generated=true
12
12
  CONTENT
13
13
  end
14
14
 
15
- sig { params(path: Pathname).void }
15
+ #: (Pathname path) -> void
16
16
  def create_vendored_attribute_file(path)
17
17
  create_gitattributes_file(path, <<~CONTENT)
18
18
  **/*.rbi linguist-vendored=true
@@ -21,7 +21,7 @@ class GitAttributes
21
21
 
22
22
  private
23
23
 
24
- sig { params(path: Pathname, content: String).void }
24
+ #: (Pathname path, String content) -> void
25
25
  def create_gitattributes_file(path, content)
26
26
  # We don't want to start creating folders, just to write
27
27
  # the `.gitattributes` file. So, if the folder doesn't