tapioca 0.11.17 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +122 -100
  3. data/lib/tapioca/commands/abstract_dsl.rb +3 -2
  4. data/lib/tapioca/commands/abstract_gem.rb +3 -1
  5. data/lib/tapioca/dsl/compilers/aasm.rb +1 -6
  6. data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +1 -5
  7. data/lib/tapioca/dsl/compilers/action_mailer.rb +1 -5
  8. data/lib/tapioca/dsl/compilers/action_text.rb +1 -5
  9. data/lib/tapioca/dsl/compilers/active_job.rb +1 -5
  10. data/lib/tapioca/dsl/compilers/active_model_attributes.rb +4 -11
  11. data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +10 -6
  12. data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +1 -5
  13. data/lib/tapioca/dsl/compilers/active_record_associations.rb +1 -5
  14. data/lib/tapioca/dsl/compilers/active_record_columns.rb +1 -5
  15. data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +1 -5
  16. data/lib/tapioca/dsl/compilers/active_record_enum.rb +1 -7
  17. data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +2 -9
  18. data/lib/tapioca/dsl/compilers/active_record_relations.rb +253 -66
  19. data/lib/tapioca/dsl/compilers/active_record_scope.rb +1 -5
  20. data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +1 -5
  21. data/lib/tapioca/dsl/compilers/active_record_store.rb +1 -5
  22. data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +1 -7
  23. data/lib/tapioca/dsl/compilers/active_resource.rb +1 -5
  24. data/lib/tapioca/dsl/compilers/active_storage.rb +1 -6
  25. data/lib/tapioca/dsl/compilers/active_support_concern.rb +1 -5
  26. data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +6 -16
  27. data/lib/tapioca/dsl/compilers/config.rb +1 -5
  28. data/lib/tapioca/dsl/compilers/frozen_record.rb +1 -5
  29. data/lib/tapioca/dsl/compilers/graphql_input_object.rb +2 -6
  30. data/lib/tapioca/dsl/compilers/graphql_mutation.rb +2 -6
  31. data/lib/tapioca/dsl/compilers/identity_cache.rb +1 -7
  32. data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +1 -7
  33. data/lib/tapioca/dsl/compilers/kredis.rb +1 -5
  34. data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +1 -5
  35. data/lib/tapioca/dsl/compilers/protobuf.rb +8 -5
  36. data/lib/tapioca/dsl/compilers/rails_generators.rb +1 -6
  37. data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +1 -5
  38. data/lib/tapioca/dsl/compilers/smart_properties.rb +1 -7
  39. data/lib/tapioca/dsl/compilers/state_machines.rb +1 -7
  40. data/lib/tapioca/dsl/compilers/url_helpers.rb +17 -16
  41. data/lib/tapioca/dsl/extensions/active_record.rb +4 -2
  42. data/lib/tapioca/dsl/extensions/frozen_record.rb +6 -2
  43. data/lib/tapioca/dsl/extensions/kredis.rb +6 -2
  44. data/lib/tapioca/dsl/helpers/active_model_type_helper.rb +70 -0
  45. data/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +3 -35
  46. data/lib/tapioca/dsl/helpers/active_record_constants_helper.rb +2 -0
  47. data/lib/tapioca/dsl/pipeline.rb +1 -1
  48. data/lib/tapioca/gem/listeners/sorbet_props.rb +2 -1
  49. data/lib/tapioca/gemfile.rb +12 -1
  50. data/lib/tapioca/rbi_ext/model.rb +38 -6
  51. data/lib/tapioca/version.rb +1 -1
  52. metadata +6 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a74fea1cf7f8de26296fa1fb617362cceac2f800740cfaac4e95b8b0106dfc9
4
- data.tar.gz: 911ce69b722d3b30d07f2806ae155e0c390d015eea45ba85bf69c0796e6b5bf5
3
+ metadata.gz: f655f69697a5c375a3e04eef733d55213d2ea83b7392f35e3f81ed61ef4f93e4
4
+ data.tar.gz: 1ba60b67539a5034080dd9247f2f005593f25bcb2f01d72b72bccfb9a1f77f73
5
5
  SHA512:
6
- metadata.gz: 3fa1c5dcd97eee61f4385ba685c8f0b7e9290bc9a79822bdf46dcbe681b7b40bcef256cf8a293911b4bcbcb39ea325b1280da1eabbfde069d6d21161d1a6a6b0
7
- data.tar.gz: b7d3e1b1e0341bd8b835daa3f4a405271a97376eca922ea46a5680b7d388560426819d77ea9b64623f91deb68d76548372b78488d626386f5cfb35ca6531934b
6
+ metadata.gz: 99e5157e6d3b82922fb321d9eed18813bd8964cd02a9e253653c73ae6fff56529638e129532bf165dae9ec43e191e9186b4e6a7e4481ea0e4f11d5e2675b2f37
7
+ data.tar.gz: 22e178bf5afe57e2fa348606bf3cdbc8085cb4e8f735cdf1ad06665e27e6b5e08085d1eef74bba823eab87b3e1f76f12c02df5455a4fd182f11455744a5ce27c
data/README.md CHANGED
@@ -40,6 +40,7 @@ Tapioca makes it easy to work with [Sorbet](https://sorbet.org) in your codebase
40
40
  * [Excluding a gem from RBI generation](#excluding-a-gem-from-rbi-generation)
41
41
  * [Changing the strictness level of the RBI for a gem](#changing-the-strictness-level-of-the-rbi-for-a-gem)
42
42
  * [Keeping RBI files for gems up-to-date](#keeping-rbi-files-for-gems-up-to-date)
43
+ * [Importing hand written signatures from gem's `rbi/` folder](#importing-hand-written-signatures-from-gems-rbi-folder)
43
44
  * [Pulling RBI annotations from remote sources](#pulling-rbi-annotations-from-remote-sources)
44
45
  * [Basic authentication](#basic-authentication)
45
46
  * [Using a .netrc file](#using-a-netrc-file)
@@ -83,10 +84,10 @@ Commands:
83
84
  tapioca todo # Generate the list of unresolved constants
84
85
 
85
86
  Options:
86
- -c, [--config=<config file path>] # Path to the Tapioca configuration file
87
- # Default: sorbet/tapioca/config.yml
88
- -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
89
- # Default: false
87
+ -c, [--config=<config file path>] # Path to the Tapioca configuration file
88
+ # Default: sorbet/tapioca/config.yml
89
+ -V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes
90
+ # Default: false
90
91
 
91
92
  ```
92
93
  <!-- END_HELP -->
@@ -117,10 +118,10 @@ Usage:
117
118
  tapioca init
118
119
 
119
120
  Options:
120
- -c, [--config=<config file path>] # Path to the Tapioca configuration file
121
- # Default: sorbet/tapioca/config.yml
122
- -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
123
- # Default: false
121
+ -c, [--config=<config file path>] # Path to the Tapioca configuration file
122
+ # Default: sorbet/tapioca/config.yml
123
+ -V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes
124
+ # Default: false
124
125
 
125
126
  Get project ready for type checking
126
127
  ```
@@ -164,43 +165,43 @@ Usage:
164
165
  tapioca gem [gem...]
165
166
 
166
167
  Options:
167
- --out, -o, [--outdir=directory] # The output directory for generated gem RBI files
168
- # Default: sorbet/rbi/gems
169
- [--file-header], [--no-file-header] # Add a "This file is generated" header on top of each generated RBI file
170
- # Default: true
171
- [--all], [--no-all] # Regenerate RBI files for all gems
172
- # Default: false
173
- --pre, -b, [--prerequire=file] # A file to be required before Bundler.require is called
174
- --post, -a, [--postrequire=file] # A file to be required after Bundler.require is called
175
- # Default: sorbet/tapioca/require.rb
176
- -x, [--exclude=gem [gem ...]] # Exclude the given gem(s) from RBI generation
177
- [--include-dependencies], [--no-include-dependencies] # Generate RBI files for dependencies of the given gem(s)
178
- # Default: false
179
- --typed, -t, [--typed-overrides=gem:level [gem:level ...]] # Override for typed sigils for generated gem RBIs
180
- # Default: {"activesupport"=>"false"}
181
- [--verify], [--no-verify] # Verify RBIs are up-to-date
182
- # Default: false
183
- [--doc], [--no-doc] # Include YARD documentation from sources when generating RBIs. Warning: this might be slow
184
- # Default: true
185
- [--loc], [--no-loc] # Include comments with source location when generating RBIs
186
- # Default: true
187
- [--exported-gem-rbis], [--no-exported-gem-rbis] # Include RBIs found in the `rbi/` directory of the gem
188
- # Default: true
189
- -w, [--workers=N] # Number of parallel workers to use when generating RBIs (default: auto)
190
- [--auto-strictness], [--no-auto-strictness] # Autocorrect strictness in gem RBIs in case of conflict with the DSL RBIs
191
- # Default: true
192
- --dsl-dir, [--dsl-dir=directory] # The DSL directory used to correct gems strictnesses
193
- # Default: sorbet/rbi/dsl
194
- [--rbi-max-line-length=N] # Set the max line length of generated RBIs. Signatures longer than the max line length will be wrapped
195
- # Default: 120
196
- -e, [--environment=ENVIRONMENT] # The Rack/Rails environment to use when generating RBIs
197
- # Default: development
198
- [--halt-upon-load-error], [--no-halt-upon-load-error] # Halt upon a load error while loading the Rails application
199
- # Default: true
200
- -c, [--config=<config file path>] # Path to the Tapioca configuration file
201
- # Default: sorbet/tapioca/config.yml
202
- -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
203
- # Default: false
168
+ --out, -o, [--outdir=directory] # The output directory for generated gem RBI files
169
+ # Default: sorbet/rbi/gems
170
+ [--file-header], [--no-file-header], [--skip-file-header] # Add a "This file is generated" header on top of each generated RBI file
171
+ # Default: true
172
+ [--all], [--no-all], [--skip-all] # Regenerate RBI files for all gems
173
+ # Default: false
174
+ --pre, -b, [--prerequire=file] # A file to be required before Bundler.require is called
175
+ --post, -a, [--postrequire=file] # A file to be required after Bundler.require is called
176
+ # Default: sorbet/tapioca/require.rb
177
+ -x, [--exclude=gem [gem ...]] # Exclude the given gem(s) from RBI generation
178
+ [--include-dependencies], [--no-include-dependencies], [--skip-include-dependencies] # Generate RBI files for dependencies of the given gem(s)
179
+ # Default: false
180
+ --typed, -t, [--typed-overrides=gem:level [gem:level ...]] # Override for typed sigils for generated gem RBIs
181
+ # Default: {"activesupport"=>"false"}
182
+ [--verify], [--no-verify], [--skip-verify] # Verify RBIs are up-to-date
183
+ # Default: false
184
+ [--doc], [--no-doc], [--skip-doc] # Include YARD documentation from sources when generating RBIs. Warning: this might be slow
185
+ # Default: true
186
+ [--loc], [--no-loc], [--skip-loc] # Include comments with source location when generating RBIs
187
+ # Default: true
188
+ [--exported-gem-rbis], [--no-exported-gem-rbis], [--skip-exported-gem-rbis] # Include RBIs found in the `rbi/` directory of the gem
189
+ # Default: true
190
+ -w, [--workers=N] # Number of parallel workers to use when generating RBIs (default: auto)
191
+ [--auto-strictness], [--no-auto-strictness], [--skip-auto-strictness] # Autocorrect strictness in gem RBIs in case of conflict with the DSL RBIs
192
+ # Default: true
193
+ --dsl-dir, [--dsl-dir=directory] # The DSL directory used to correct gems strictnesses
194
+ # Default: sorbet/rbi/dsl
195
+ [--rbi-max-line-length=N] # Set the max line length of generated RBIs. Signatures longer than the max line length will be wrapped
196
+ # Default: 120
197
+ -e, [--environment=ENVIRONMENT] # The Rack/Rails environment to use when generating RBIs
198
+ # Default: development
199
+ [--halt-upon-load-error], [--no-halt-upon-load-error], [--skip-halt-upon-load-error] # Halt upon a load error while loading the Rails application
200
+ # Default: true
201
+ -c, [--config=<config file path>] # Path to the Tapioca configuration file
202
+ # Default: sorbet/tapioca/config.yml
203
+ -V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes
204
+ # Default: false
204
205
 
205
206
  Generate RBIs from gems
206
207
  ```
@@ -223,18 +224,18 @@ For gems that have a normal default `require` and that load all of their constan
223
224
  For example, suppose you are using the class `BetterHtml::Parser` exported from the `better_html` gem. Just doing a `require "better_html"` (which is the default require) does not load that type:
224
225
 
225
226
  ```shell
226
- $ bundle exec pry
227
+ $ bundle exec irb
227
228
 
228
- [1] pry(main)> require 'better_html'
229
+ irb(main):001> require 'better_html'
229
230
  => true
230
- [2] pry(main)> BetterHtml
231
+ irb(main):002> BetterHtml
231
232
  => BetterHtml
232
- [3] pry(main)> BetterHtml::Parser
233
- NameError: uninitialized constant BetterHtml::Parser
234
- from (pry):3:in `__pry__`
235
- [4] pry(main)> require 'better_html/parser'
233
+ irb(main):003> BetterHtml::Parser
234
+ (irb):3:in '<main>': uninitialized constant BetterHtml::Parser (NameError)
235
+ Did you mean? BetterHtml::ParserError
236
+ irb(main):004> require 'better_html/parser'
236
237
  => true
237
- [5] pry(main)> BetterHtml::Parser
238
+ irb(main):005> BetterHtml::Parser
238
239
  => BetterHtml::Parser
239
240
  ```
240
241
 
@@ -315,7 +316,7 @@ gem:
315
316
 
316
317
  #### Keeping RBI files for gems up-to-date
317
318
 
318
- To ensure all RBI files for gems are up-to-date with the latest changes in your `Gemfile.lock`, Tapioca provides a `--verify` option:
319
+ To ensure all RBI files for gems are present and have the correct version based on your `Gemfile.lock`, Tapioca provides a `--verify` option:
319
320
 
320
321
  ```shell
321
322
  $ bin/tapioca gems --verify
@@ -325,7 +326,16 @@ Checking for out-of-date RBIs...
325
326
  Nothing to do, all RBIs are up-to-date.
326
327
  ```
327
328
 
328
- This option can be used on CI to make sure the RBI files are always up-to-date and ensure accurate type checking. **Warning**: doing so will break your normal Dependabot workflow as every pull-request opened to bump a gem version will fail CI since the RBI will be out-of-date and will require you to manually run `bin/tapioca gems` to update them.
329
+ This option can be used in CI to make sure the RBI files are *up-to-date* and ensure accurate type checking.
330
+
331
+ **Warning**: doing so will break your normal automated dependency update workflow as every pull request opened to bump a gem version will fail CI since the RBI will be out-of-date. You will need to either set up additional automation (eg [Dependabot](https://github.com/dependabot/dependabot-core/issues/5962#issuecomment-1303781931)), or manually run `bin/tapioca gems` and commit the results.
332
+
333
+ **Warning**: Verification ONLY ensures the RBI files are present, used and have the correct version based on the gem version in your `Gemfile.lock`. It's possible for your RBIs to be out-of-date if RBIs were not regenerated following an update to tapioca itself or if a another gem that injects functionality (e.g. `turbo-rails`) was installed/updated/removed. To ensure RBIs are completely up-to-date, you must run `bin/tapioca gems --all` but it's not recommended to do this in CI as it's an expensive operation.
334
+
335
+
336
+ #### Importing hand written signatures from gem's `rbi/` folder
337
+
338
+ Tapioca will import any signatures found in the `rbi/` folder of a given gem and combine them with the RBIs it generates. This is useful when a gem doesn't want to depend on `sorbet-runtime` but still wants to provide type safety to users during static checks. Note that the `rbi/` folder needs to be included in the gem release using the `.gemspec` file. Applications can choose not to import these signatures using the `--no-exported-gem-rbis` flag.
329
339
 
330
340
  ### Pulling RBI annotations from remote sources
331
341
 
@@ -357,14 +367,14 @@ Usage:
357
367
  Options:
358
368
  [--sources=one two three] # URIs of the sources to pull gem RBI annotations from
359
369
  # Default: "https://raw.githubusercontent.com/Shopify/rbi-central/main"
360
- [--netrc], [--no-netrc] # Use .netrc to authenticate to private sources
370
+ [--netrc], [--no-netrc], [--skip-netrc] # Use .netrc to authenticate to private sources
361
371
  # Default: true
362
372
  [--netrc-file=NETRC_FILE] # Path to .netrc file
363
373
  [--auth=AUTH] # HTTP authorization header for private sources
364
374
  --typed, -t, [--typed-overrides=gem:level [gem:level ...]] # Override for typed sigils for pulled annotations
365
375
  -c, [--config=<config file path>] # Path to the Tapioca configuration file
366
376
  # Default: sorbet/tapioca/config.yml
367
- -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
377
+ -V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes
368
378
  # Default: false
369
379
 
370
380
  Pull gem RBI annotations from remote sources
@@ -467,32 +477,32 @@ Usage:
467
477
  tapioca dsl [constant...]
468
478
 
469
479
  Options:
470
- --out, -o, [--outdir=directory] # The output directory for generated DSL RBI files
471
- # Default: sorbet/rbi/dsl
472
- [--file-header], [--no-file-header] # Add a "This file is generated" header on top of each generated RBI file
473
- # Default: true
474
- [--only=compiler [compiler ...]] # Only run supplied DSL compiler(s)
475
- [--exclude=compiler [compiler ...]] # Exclude supplied DSL compiler(s)
476
- [--verify], [--no-verify] # Verifies RBIs are up-to-date
477
- # Default: false
478
- -q, [--quiet], [--no-quiet] # Suppresses file creation output
479
- # Default: false
480
- -w, [--workers=N] # Number of parallel workers to use when generating RBIs (default: 2)
481
- # Default: 2
482
- [--rbi-max-line-length=N] # Set the max line length of generated RBIs. Signatures longer than the max line length will be wrapped
483
- # Default: 120
484
- -e, [--environment=ENVIRONMENT] # The Rack/Rails environment to use when generating RBIs
485
- # Default: development
486
- -l, [--list-compilers], [--no-list-compilers] # List all loaded compilers
487
- # Default: false
488
- [--app-root=APP_ROOT] # The path to the Rails application
489
- # Default: .
490
- [--halt-upon-load-error], [--no-halt-upon-load-error] # Halt upon a load error while loading the Rails application
491
- # Default: true
492
- -c, [--config=<config file path>] # Path to the Tapioca configuration file
493
- # Default: sorbet/tapioca/config.yml
494
- -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
495
- # Default: false
480
+ --out, -o, [--outdir=directory] # The output directory for generated DSL RBI files
481
+ # Default: sorbet/rbi/dsl
482
+ [--file-header], [--no-file-header], [--skip-file-header] # Add a "This file is generated" header on top of each generated RBI file
483
+ # Default: true
484
+ [--only=compiler [compiler ...]] # Only run supplied DSL compiler(s)
485
+ [--exclude=compiler [compiler ...]] # Exclude supplied DSL compiler(s)
486
+ [--verify], [--no-verify], [--skip-verify] # Verifies RBIs are up-to-date
487
+ # Default: false
488
+ -q, [--quiet], [--no-quiet], [--skip-quiet] # Suppresses file creation output
489
+ # Default: false
490
+ -w, [--workers=N] # Number of parallel workers to use when generating RBIs (default: 2)
491
+ # Default: 2
492
+ [--rbi-max-line-length=N] # Set the max line length of generated RBIs. Signatures longer than the max line length will be wrapped
493
+ # Default: 120
494
+ -e, [--environment=ENVIRONMENT] # The Rack/Rails environment to use when generating RBIs
495
+ # Default: development
496
+ -l, [--list-compilers], [--no-list-compilers], [--skip-list-compilers] # List all loaded compilers
497
+ # Default: false
498
+ [--app-root=APP_ROOT] # The path to the Rails application
499
+ # Default: .
500
+ [--halt-upon-load-error], [--no-halt-upon-load-error], [--skip-halt-upon-load-error] # Halt upon a load error while loading the Rails application
501
+ # Default: true
502
+ -c, [--config=<config file path>] # Path to the Tapioca configuration file
503
+ # Default: sorbet/tapioca/config.yml
504
+ -V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes
505
+ # Default: false
496
506
 
497
507
  Generate RBIs for dynamic methods
498
508
  ```
@@ -521,6 +531,18 @@ Reason:
521
531
 
522
532
  This option can be used on CI to make sure the RBI files are always up-to-date and ensure accurate type checking.
523
533
 
534
+ If you are using Rails, you can configure `tapioca dsl` to run after each migration:
535
+
536
+ ```ruby
537
+ # Rakefile
538
+ if Rails.env.development?
539
+ namespace :db do
540
+ task :migrate do # Appends to the existing `db:migrate` task
541
+ system("bundle exec tapioca dsl", exception: true)
542
+ end
543
+ end
544
+ ```
545
+
524
546
  #### Writing custom DSL compilers
525
547
 
526
548
  It is possible to create your own compilers for DSLs not supported by Tapioca out of the box.
@@ -840,23 +862,23 @@ Usage:
840
862
  tapioca check-shims
841
863
 
842
864
  Options:
843
- [--gem-rbi-dir=GEM_RBI_DIR] # Path to gem RBIs
844
- # Default: sorbet/rbi/gems
845
- [--dsl-rbi-dir=DSL_RBI_DIR] # Path to DSL RBIs
846
- # Default: sorbet/rbi/dsl
847
- [--shim-rbi-dir=SHIM_RBI_DIR] # Path to shim RBIs
848
- # Default: sorbet/rbi/shims
849
- [--annotations-rbi-dir=ANNOTATIONS_RBI_DIR] # Path to annotations RBIs
850
- # Default: sorbet/rbi/annotations
851
- [--todo-rbi-file=TODO_RBI_FILE] # Path to the generated todo RBI file
852
- # Default: sorbet/rbi/todo.rbi
853
- [--payload], [--no-payload] # Check shims against Sorbet's payload
854
- # Default: true
855
- -w, [--workers=N] # Number of parallel workers (default: auto)
856
- -c, [--config=<config file path>] # Path to the Tapioca configuration file
857
- # Default: sorbet/tapioca/config.yml
858
- -V, [--verbose], [--no-verbose] # Verbose output for debugging purposes
859
- # Default: false
865
+ [--gem-rbi-dir=GEM_RBI_DIR] # Path to gem RBIs
866
+ # Default: sorbet/rbi/gems
867
+ [--dsl-rbi-dir=DSL_RBI_DIR] # Path to DSL RBIs
868
+ # Default: sorbet/rbi/dsl
869
+ [--shim-rbi-dir=SHIM_RBI_DIR] # Path to shim RBIs
870
+ # Default: sorbet/rbi/shims
871
+ [--annotations-rbi-dir=ANNOTATIONS_RBI_DIR] # Path to annotations RBIs
872
+ # Default: sorbet/rbi/annotations
873
+ [--todo-rbi-file=TODO_RBI_FILE] # Path to the generated todo RBI file
874
+ # Default: sorbet/rbi/todo.rbi
875
+ [--payload], [--no-payload], [--skip-payload] # Check shims against Sorbet's payload
876
+ # Default: true
877
+ -w, [--workers=N] # Number of parallel workers (default: auto)
878
+ -c, [--config=<config file path>] # Path to the Tapioca configuration file
879
+ # Default: sorbet/tapioca/config.yml
880
+ -V, [--verbose], [--no-verbose], [--skip-verbose] # Verbose output for debugging purposes
881
+ # Default: false
860
882
 
861
883
  Check duplicated definitions in shim RBIs
862
884
  ```
@@ -175,10 +175,11 @@ module Tapioca
175
175
 
176
176
  unless unprocessable_compilers.empty?
177
177
  message = unprocessable_compilers.map do |name, _|
178
- set_color("Error: Cannot find compiler '#{name}'", :red)
178
+ set_color("Warning: Cannot find compiler '#{name}'", :yellow)
179
179
  end.join("\n")
180
180
 
181
- raise Thor::Error, message
181
+ say(message)
182
+ say("")
182
183
  end
183
184
 
184
185
  T.cast(compiler_map.values, T::Array[T.class_of(Tapioca::Dsl::Compiler)])
@@ -118,7 +118,9 @@ module Tapioca
118
118
  reason: "types exported from the `#{gem.name}` gem",
119
119
  ) if @file_header
120
120
 
121
- rbi.root = Tapioca::Gem::Pipeline.new(gem, include_doc: @include_doc, include_loc: @include_loc).compile
121
+ rbi.root = Runtime::Trackers::Autoload.with_disabled_exits do
122
+ Tapioca::Gem::Pipeline.new(gem, include_doc: @include_doc, include_loc: @include_loc).compile
123
+ end
122
124
 
123
125
  merge_with_exported_rbi(gem, rbi) if @include_exported_rbis
124
126
 
@@ -1,12 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "active_record"
6
- require "aasm"
7
- rescue LoadError
8
- return
9
- end
4
+ return unless defined?(AASM)
10
5
 
11
6
  module Tapioca
12
7
  module Dsl
@@ -1,11 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "action_controller"
6
- rescue LoadError
7
- return
8
- end
4
+ return unless defined?(ActionController::Base)
9
5
 
10
6
  module Tapioca
11
7
  module Dsl
@@ -1,11 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "action_mailer"
6
- rescue LoadError
7
- return
8
- end
4
+ return unless defined?(ActionMailer::Base)
9
5
 
10
6
  module Tapioca
11
7
  module Dsl
@@ -1,11 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "action_text"
6
- rescue LoadError
7
- return
8
- end
4
+ return unless defined?(ActiveRecord::Base)
9
5
 
10
6
  module Tapioca
11
7
  module Dsl
@@ -1,11 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "active_job"
6
- rescue LoadError
7
- return
8
- end
4
+ return unless defined?(ActiveJob::Base)
9
5
 
10
6
  module Tapioca
11
7
  module Dsl
@@ -1,11 +1,9 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "active_model"
6
- rescue LoadError
7
- return
8
- end
4
+ return unless defined?(ActiveModel::Attributes)
5
+
6
+ require "tapioca/dsl/helpers/active_model_type_helper"
9
7
 
10
8
  module Tapioca
11
9
  module Dsl
@@ -103,11 +101,6 @@ module Tapioca
103
101
 
104
102
  sig { params(attribute_type_value: T.untyped).returns(::String) }
105
103
  def type_for(attribute_type_value)
106
- # This guarantees that the type will remain as T.untyped for attributes in the following form:
107
- # attribute :name
108
- # This is because for a generic attribute with no specified type, ActiveModel::Type::Value.new is returned
109
- return "T.untyped" if attribute_type_value.instance_of?(ActiveModel::Type::Value)
110
-
111
104
  type = case attribute_type_value
112
105
  when ActiveModel::Type::Boolean
113
106
  "T::Boolean"
@@ -124,7 +117,7 @@ module Tapioca
124
117
  when ActiveModel::Type::String
125
118
  "::String"
126
119
  else
127
- attribute_type_value.class.name.to_s
120
+ Helpers::ActiveModelTypeHelper.type_for(attribute_type_value)
128
121
  end
129
122
 
130
123
  as_nilable_type(type)
@@ -1,11 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "active_model"
6
- rescue LoadError
7
- return
8
- end
4
+ return unless defined?(ActiveModel::SecurePassword)
9
5
 
10
6
  module Tapioca
11
7
  module Dsl
@@ -82,7 +78,15 @@ module Tapioca
82
78
 
83
79
  root.create_path(constant) do |klass|
84
80
  methods.each do |method|
85
- create_method_from_def(klass, constant.instance_method(method))
81
+ if method == :authenticate || method.start_with?("authenticate_")
82
+ klass.create_method(
83
+ method.to_s,
84
+ parameters: [create_param("unencrypted_password", type: "T.untyped")],
85
+ return_type: "T.any(#{constant}, FalseClass)",
86
+ )
87
+ else
88
+ create_method_from_def(klass, constant.instance_method(method))
89
+ end
86
90
  end
87
91
  end
88
92
  end
@@ -1,11 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "active_model"
6
- rescue LoadError
7
- return
8
- end
4
+ return unless defined?(ActiveModel::Validations)
9
5
 
10
6
  module Tapioca
11
7
  module Dsl
@@ -1,11 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "active_record"
6
- rescue LoadError
7
- return
8
- end
4
+ return unless defined?(ActiveRecord::Base)
9
5
 
10
6
  require "tapioca/dsl/helpers/active_record_constants_helper"
11
7
 
@@ -1,11 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "active_record"
6
- rescue LoadError
7
- return
8
- end
4
+ return unless defined?(ActiveRecord::Base)
9
5
 
10
6
  require "tapioca/dsl/helpers/active_record_column_type_helper"
11
7
  require "tapioca/dsl/helpers/active_record_constants_helper"
@@ -1,11 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "active_record"
6
- rescue LoadError
7
- return
8
- end
4
+ return unless defined?(ActiveRecord::Base)
9
5
 
10
6
  require "tapioca/dsl/helpers/active_record_column_type_helper"
11
7
  require "tapioca/dsl/helpers/active_record_constants_helper"
@@ -1,13 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "active_record"
6
- rescue LoadError
7
- # means ActiveRecord is not installed,
8
- # so let's not even define the compiler.
9
- return
10
- end
4
+ return unless defined?(ActiveRecord::Base)
11
5
 
12
6
  module Tapioca
13
7
  module Dsl
@@ -1,14 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- require "rails"
6
- require "active_record"
7
- require "active_record/fixtures"
8
- require "active_support/test_case"
9
- rescue LoadError
10
- return
11
- end
4
+ return unless defined?(Rails) && defined?(ActiveSupport::TestCase) && defined?(ActiveRecord::TestFixtures)
12
5
 
13
6
  module Tapioca
14
7
  module Dsl
@@ -62,7 +55,7 @@ module Tapioca
62
55
 
63
56
  sig { override.returns(T::Enumerable[Module]) }
64
57
  def gather_constants
65
- return [] unless Rails.application
58
+ return [] unless defined?(Rails.application) && Rails.application
66
59
 
67
60
  [ActiveSupport::TestCase]
68
61
  end