sorbet-rails 0.7.3 → 0.7.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/ci-master.yml +30 -0
- data/.github/workflows/ci.yml +26 -0
- data/.github/workflows/publish-gem.yml +17 -0
- data/CONTRIBUTING.md +1 -2
- data/Gemfile +5 -9
- data/README.md +44 -6
- data/Rakefile +13 -24
- data/lib/sorbet-rails/active_record_rbi_formatter.rb +18 -15
- data/lib/sorbet-rails/dependent_gem_rbis/activerecord.rbi +4 -0
- data/lib/sorbet-rails/dependent_gem_rbis/parlour.rbi +1896 -0
- data/lib/sorbet-rails/gem_plugins/aasm_plugin.rb +55 -0
- data/lib/sorbet-rails/gem_plugins/attr_json_plugin.rb +137 -0
- data/lib/sorbet-rails/gem_plugins/flag_shih_tzu_plugin.rb +201 -0
- data/lib/sorbet-rails/gem_plugins/kaminari_plugin.rb +20 -0
- data/lib/sorbet-rails/gem_plugins/money_rails_plugin.rb +76 -0
- data/lib/sorbet-rails/gem_plugins/shrine_plugin.rb +1 -1
- data/lib/sorbet-rails/job_rbi_formatter.rb +1 -1
- data/lib/sorbet-rails/model_column_utils.rb +1 -1
- data/lib/sorbet-rails/model_plugins/active_record_assoc.rb +1 -1
- data/lib/sorbet-rails/model_plugins/active_record_querying.rb +38 -1
- data/lib/sorbet-rails/model_plugins/active_record_serialized_attribute.rb +3 -2
- data/lib/sorbet-rails/model_plugins/base.rb +8 -1
- data/lib/sorbet-rails/model_plugins/custom_finder_methods.rb +1 -1
- data/lib/sorbet-rails/model_plugins/plugins.rb +12 -0
- data/lib/sorbet-rails/model_rbi_formatter.rb +7 -4
- data/lib/sorbet-rails/model_utils.rb +14 -7
- data/lib/sorbet-rails/rails_mixins/custom_finder_methods.rb +12 -0
- data/lib/sorbet-rails/railtie.rb +1 -1
- data/lib/sorbet-rails/routes_rbi_formatter.rb +8 -0
- data/lib/sorbet-rails/tasks/rails_rbi.rake +12 -8
- data/sorbet-rails.gemspec +3 -3
- data/spec/bin/run_all_specs.sh +3 -4
- data/spec/bin/run_spec.sh +4 -1
- data/spec/custom_finder_methods_spec.rb +23 -0
- data/spec/generators/rails-template.rb +3 -20
- data/spec/generators/sorbet_test_cases.rb +26 -4
- data/spec/rails_helper.rb +6 -10
- data/spec/rake_rails_rbi_models_spec.rb +11 -4
- data/spec/sorbet_spec.rb +5 -1
- data/spec/support/v5.2/Gemfile +1 -3
- data/spec/support/v5.2/Gemfile.lock +88 -81
- data/spec/support/v5.2/app/controllers/application_controller.rb +1 -1
- data/spec/support/v5.2/app/mailers/application_mailer.rb +1 -1
- data/spec/support/v5.2/app/mailers/daily_prophet_mailer.rb +1 -1
- data/spec/support/v5.2/app/mailers/hogwarts_acceptance_mailer.rb +1 -1
- data/spec/support/v5.2/app/models/spell_book.rb +1 -1
- data/spec/support/v5.2/app/models/wand.rb +1 -1
- data/spec/support/v5.2/app/models/wizard.rb +1 -1
- data/spec/support/v5.2/config/environments/development.rb +1 -1
- data/spec/support/v5.2/config/environments/production.rb +1 -1
- data/spec/support/v5.2/config/environments/test.rb +1 -1
- data/spec/support/v5.2/config/initializers/wrap_parameters.rb +1 -1
- data/spec/support/v5.2/config/routes.rb +1 -1
- data/spec/support/v5.2/sorbet_test_cases.rb +26 -4
- data/spec/support/v6.0/Gemfile +1 -1
- data/spec/support/v6.0/Gemfile.lock +103 -96
- data/spec/support/v6.0/app/mailers/application_mailer.rb +1 -1
- data/spec/support/v6.0/config/environments/development.rb +1 -1
- data/spec/support/v6.0/config/environments/test.rb +1 -1
- data/spec/support/v6.0/config/initializers/cookies_serializer.rb +1 -1
- data/spec/support/v6.0/config/initializers/sorbet_rails.rb +1 -1
- data/spec/support/v6.0/config/routes.rb +1 -1
- data/spec/support/v6.0/sorbet_test_cases.rb +26 -4
- data/spec/support/{v5.1 → v6.1}/.gitignore +13 -2
- data/spec/support/{v5.1 → v6.1}/Gemfile +12 -15
- data/spec/support/v6.1/Gemfile.lock +203 -0
- data/spec/support/{v5.0 → v6.1}/README.md +0 -0
- data/spec/support/{v5.0 → v6.1}/Rakefile +0 -0
- data/spec/support/{v5.0 → v6.1}/app/assets/config/manifest.js +0 -0
- data/spec/support/{v5.0 → v6.1}/app/assets/images/.keep +0 -0
- data/spec/support/{v5.1 → v6.1}/app/assets/stylesheets/application.css +0 -0
- data/spec/support/{v5.0 → v6.1}/app/controllers/application_controller.rb +1 -2
- data/spec/support/{v5.0 → v6.1}/app/controllers/concerns/.keep +0 -0
- data/spec/support/{v5.0 → v6.1}/app/helpers/application_helper.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/helpers/bar_helper.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/helpers/baz_helper.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/helpers/foo_helper.rb +0 -0
- data/spec/support/v6.1/app/jobs/application_job.rb +8 -0
- data/spec/support/{v5.0 → v6.1}/app/jobs/award_house_point_hourglasses.rb +0 -0
- data/spec/support/{v5.1 → v6.1}/app/mailers/application_mailer.rb +1 -1
- data/spec/support/{v5.0 → v6.1}/app/mailers/daily_prophet_mailer.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/mailers/hogwarts_acceptance_mailer.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/models/application_record.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/models/concerns/.keep +0 -0
- data/spec/support/{v5.0 → v6.1}/app/models/concerns/mythical.rb +0 -0
- data/spec/support/{v5.1 → v6.1}/app/models/headmaster.rb +1 -1
- data/spec/support/{v5.1 → v6.1}/app/models/potion.rb +0 -0
- data/spec/support/{v5.1 → v6.1}/app/models/robe.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/models/school.rb +1 -1
- data/spec/support/{v5.1 → v6.1}/app/models/spell.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/models/spell_book.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/models/squib.rb +0 -0
- data/spec/support/{v5.1 → v6.1}/app/models/subject.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/models/wand.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/models/wizard.rb +2 -1
- data/spec/support/{v5.1 → v6.1}/app/views/layouts/application.html.erb +2 -1
- data/spec/support/{v5.0 → v6.1}/app/views/layouts/mailer.html.erb +0 -0
- data/spec/support/{v5.0 → v6.1}/app/views/layouts/mailer.text.erb +0 -0
- data/spec/support/v6.1/bin/bundle +114 -0
- data/spec/support/{v5.0 → v6.1}/bin/rails +0 -0
- data/spec/support/{v5.0 → v6.1}/bin/rake +0 -0
- data/spec/support/{v5.1 → v6.1}/bin/setup +6 -11
- data/spec/support/{v5.1 → v6.1}/config/application.rb +8 -4
- data/spec/support/{v5.0 → v6.1}/config/boot.rb +0 -0
- data/spec/support/{v5.1 → v6.1}/config/database.yml +1 -1
- data/spec/support/{v5.0 → v6.1}/config/environment.rb +0 -0
- data/spec/support/{v5.1 → v6.1}/config/environments/development.rb +12 -4
- data/spec/support/{v5.1 → v6.1}/config/environments/production.rb +29 -7
- data/spec/support/{v5.1 → v6.1}/config/environments/test.rb +13 -7
- data/spec/support/{v5.0 → v6.1}/config/initializers/application_controller_renderer.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/support/v6.1/config/initializers/content_security_policy.rb +29 -0
- data/spec/support/{v5.1 → v6.1}/config/initializers/cookies_serializer.rb +1 -1
- data/spec/support/{v5.0 → v6.1}/config/initializers/filter_parameter_logging.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/config/initializers/inflections.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/config/initializers/mime_types.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/config/initializers/sorbet_rails.rb +1 -1
- data/spec/support/{v5.0 → v6.1}/config/initializers/wrap_parameters.rb +1 -1
- data/spec/support/{v5.1 → v6.1}/config/locales/en.yml +1 -1
- data/spec/support/{v5.1 → v6.1}/config/puma.rb +8 -26
- data/spec/support/v6.1/config/routes.rb +5 -0
- data/spec/support/v6.1/config/storage.yml +34 -0
- data/spec/support/{v5.0 → v6.1}/config.ru +0 -0
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000001_create_wizards.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000002_create_wands.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000003_create_spell_books.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000004_add_more_column_types_to_wands.rb +2 -2
- data/spec/support/v6.1/db/migrate/20190620000005_add_broom_to_wizard.rb +6 -0
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000006_add_more_enums_to_wizard.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000007_add_type_to_wizard.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000008_add_robe_to_wizard.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000009_add_school.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000010_add_subject.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000011_add_subjects_wizards.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000012_add_spell.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000013_add_spells_spell_books.rb +2 -2
- data/spec/support/{v5.0 → v6.1}/db/migrate/20190620000014_create_headmasters.rb +2 -2
- data/spec/support/{v5.0 → v6.1}/db/migrate/20190620000015_add_serialized_to_wizards.rb +2 -2
- data/spec/support/{v5.1 → v6.1}/db/schema.rb +14 -11
- data/spec/support/{v5.0 → v6.1}/db/seeds.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/lib/assets/.keep +0 -0
- data/spec/support/{v5.0 → v6.1}/lib/mythical_rbi_plugin.rb +0 -0
- data/spec/support/{v5.0 → v6.1}/lib/tasks/.keep +0 -0
- data/spec/support/{v5.0 → v6.1}/log/.keep +0 -0
- data/spec/support/{v5.0 → v6.1}/sorbet_test_cases.rb +29 -4
- data/spec/support/{v5.0/tmp → v6.1/storage}/.keep +0 -0
- data/spec/support/{v5.0/vendor/assets/stylesheets → v6.1/tmp}/.keep +0 -0
- data/spec/support/{v5.1/app/assets/images → v6.1/tmp/pids}/.keep +0 -0
- data/spec/support/{v5.1/app/controllers/concerns → v6.1/vendor}/.keep +0 -0
- data/spec/test_data/v5.2/expected_active_record_base.rbi +10 -10
- data/spec/test_data/v5.2/expected_active_record_relation.rbi +12 -13
- data/spec/test_data/v5.2/expected_attachment.rbi +16 -10
- data/spec/test_data/v5.2/expected_blob.rbi +16 -10
- data/spec/test_data/v5.2/expected_habtm_subjects.rbi +3 -3
- data/spec/test_data/v5.2/expected_habtm_wizards.rbi +3 -3
- data/spec/test_data/v5.2/expected_headmaster.rbi +16 -10
- data/spec/test_data/v5.2/expected_internal_metadata.rbi +16 -10
- data/spec/test_data/v5.2/expected_potion.rbi +16 -10
- data/spec/test_data/v5.2/expected_robe.rbi +16 -10
- data/spec/test_data/v5.2/expected_routes.rbi +8 -0
- data/spec/test_data/v5.2/expected_schema_migration.rbi +16 -10
- data/spec/test_data/v5.2/expected_school.rbi +16 -10
- data/spec/test_data/v5.2/expected_spell/habtm_spell_books.rbi +16 -10
- data/spec/test_data/v5.2/expected_spell.rbi +16 -10
- data/spec/test_data/v5.2/expected_spell_book/habtm_spell_books.rbi +3 -3
- data/spec/test_data/v5.2/expected_spell_book/habtm_spells.rbi +16 -10
- data/spec/test_data/v5.2/expected_spell_book.rbi +16 -10
- data/spec/test_data/v5.2/expected_squib.rbi +18 -12
- data/spec/test_data/v5.2/expected_subject/habtm_wizards.rbi +16 -10
- data/spec/test_data/v5.2/expected_subject.rbi +16 -10
- data/spec/test_data/v5.2/expected_wand.rbi +16 -10
- data/spec/test_data/v5.2/expected_wizard/habtm_subjects.rbi +16 -10
- data/spec/test_data/v5.2/expected_wizard.rbi +18 -12
- data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +21 -15
- data/spec/test_data/v6.0/expected_active_record_base.rbi +10 -10
- data/spec/test_data/v6.0/expected_active_record_relation.rbi +12 -13
- data/spec/test_data/v6.0/expected_attachment.rbi +16 -10
- data/spec/test_data/v6.0/expected_blob.rbi +16 -10
- data/spec/test_data/v6.0/expected_habtm_subjects.rbi +3 -3
- data/spec/test_data/v6.0/expected_habtm_wizards.rbi +3 -3
- data/spec/test_data/v6.0/expected_headmaster.rbi +16 -10
- data/spec/test_data/v6.0/expected_internal_metadata.rbi +16 -10
- data/spec/test_data/v6.0/expected_potion.rbi +16 -10
- data/spec/test_data/v6.0/expected_robe.rbi +16 -10
- data/spec/test_data/v6.0/expected_routes.rbi +8 -0
- data/spec/test_data/v6.0/expected_schema_migration.rbi +16 -10
- data/spec/test_data/v6.0/expected_school.rbi +16 -10
- data/spec/test_data/v6.0/expected_spell/habtm_spell_books.rbi +16 -10
- data/spec/test_data/v6.0/expected_spell.rbi +16 -10
- data/spec/test_data/v6.0/expected_spell_book/habtm_spell_books.rbi +3 -3
- data/spec/test_data/v6.0/expected_spell_book/habtm_spells.rbi +16 -10
- data/spec/test_data/v6.0/expected_spell_book.rbi +16 -10
- data/spec/test_data/v6.0/expected_squib.rbi +18 -12
- data/spec/test_data/v6.0/expected_subject/habtm_wizards.rbi +16 -10
- data/spec/test_data/v6.0/expected_subject.rbi +16 -10
- data/spec/test_data/v6.0/expected_wand.rbi +16 -10
- data/spec/test_data/v6.0/expected_wizard/habtm_subjects.rbi +16 -10
- data/spec/test_data/v6.0/expected_wizard.rbi +18 -12
- data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +21 -15
- data/spec/test_data/{v5.1 → v6.1}/expected_active_record_base.rbi +16 -16
- data/spec/test_data/{v5.1 → v6.1}/expected_active_record_relation.rbi +28 -32
- data/spec/test_data/{v5.0 → v6.1}/expected_application_job.rbi +0 -0
- data/spec/test_data/{v5.0 → v6.1}/expected_application_mailer.rbi +0 -0
- data/spec/test_data/v6.1/expected_attachment.rbi +340 -0
- data/spec/test_data/{v5.0 → v6.1}/expected_award_house_point_hourglasses.rbi +0 -0
- data/spec/test_data/v6.1/expected_blob.rbi +388 -0
- data/spec/test_data/{v5.0 → v6.1}/expected_custom_application_job.rbi +0 -0
- data/spec/test_data/{v5.0 → v6.1}/expected_custom_application_mailer.rbi +0 -0
- data/spec/test_data/{v5.0 → v6.1}/expected_custom_award_house_point_hourglasses.rbi +0 -0
- data/spec/test_data/{v5.0 → v6.1}/expected_custom_daily_prophet_mailer.rbi +0 -0
- data/spec/test_data/{v5.0 → v6.1}/expected_custom_hogwarts_acceptance_mailer.rbi +0 -0
- data/spec/test_data/{v5.0 → v6.1}/expected_daily_prophet_mailer.rbi +0 -0
- data/spec/test_data/{v5.1 → v6.1}/expected_habtm_subjects.rbi +51 -3
- data/spec/test_data/{v5.1 → v6.1}/expected_habtm_wizards.rbi +51 -3
- data/spec/test_data/{v5.1 → v6.1}/expected_headmaster.rbi +42 -6
- data/spec/test_data/{v5.0 → v6.1}/expected_helpers.rbi +0 -0
- data/spec/test_data/{v5.0 → v6.1}/expected_helpers_with_application_and_devise_helpers.rbi +0 -0
- data/spec/test_data/{v5.0 → v6.1}/expected_hogwarts_acceptance_mailer.rbi +0 -0
- data/spec/test_data/{v5.1 → v6.1}/expected_internal_metadata.rbi +42 -6
- data/spec/test_data/{v5.0 → v6.1}/expected_no_routes.rbi +0 -0
- data/spec/test_data/{v5.1 → v6.1}/expected_potion.rbi +42 -6
- data/spec/test_data/v6.1/expected_record.rbi +301 -0
- data/spec/test_data/{v5.1 → v6.1}/expected_robe.rbi +42 -6
- data/spec/test_data/v6.1/expected_routes.rbi +175 -0
- data/spec/test_data/{v5.1 → v6.1}/expected_schema_migration.rbi +42 -6
- data/spec/test_data/{v5.1 → v6.1}/expected_school.rbi +42 -6
- data/spec/test_data/{v5.1 → v6.1}/expected_spell/habtm_spell_books.rbi +42 -6
- data/spec/test_data/{v5.1 → v6.1}/expected_spell.rbi +42 -6
- data/spec/test_data/{v5.1 → v6.1}/expected_spell_book/habtm_spell_books.rbi +51 -3
- data/spec/test_data/{v5.1 → v6.1}/expected_spell_book/habtm_spells.rbi +42 -6
- data/spec/test_data/{v5.1 → v6.1}/expected_spell_book.rbi +78 -6
- data/spec/test_data/{v5.1 → v6.1}/expected_squib.rbi +514 -64
- data/spec/test_data/{v5.0 → v6.1}/expected_srb_tc_output.txt +0 -0
- data/spec/test_data/{v5.1 → v6.1}/expected_subject/habtm_wizards.rbi +42 -6
- data/spec/test_data/{v5.1 → v6.1}/expected_subject.rbi +42 -6
- data/spec/test_data/v6.1/expected_variant_record.rbi +376 -0
- data/spec/test_data/{v5.1 → v6.1}/expected_wand.rbi +108 -6
- data/spec/test_data/{v5.1 → v6.1}/expected_wizard/habtm_subjects.rbi +42 -6
- data/spec/test_data/{v5.1 → v6.1}/expected_wizard.rbi +514 -64
- data/spec/test_data/{v5.1 → v6.1}/expected_wizard_wo_spellbook.rbi +508 -58
- metadata +271 -503
- data/.travis.yml +0 -42
- data/lib/sorbet-rails/type_assert/actionpack.rbi +0 -4
- data/spec/support/v5.0/.gitignore +0 -21
- data/spec/support/v5.0/Gemfile +0 -37
- data/spec/support/v5.0/Gemfile.lock +0 -158
- data/spec/support/v5.0/app/assets/stylesheets/application.css +0 -15
- data/spec/support/v5.0/app/jobs/application_job.rb +0 -3
- data/spec/support/v5.0/app/mailers/application_mailer.rb +0 -5
- data/spec/support/v5.0/app/models/headmaster.rb +0 -8
- data/spec/support/v5.0/app/models/potion.rb +0 -6
- data/spec/support/v5.0/app/models/robe.rb +0 -4
- data/spec/support/v5.0/app/models/spell.rb +0 -5
- data/spec/support/v5.0/app/models/subject.rb +0 -5
- data/spec/support/v5.0/app/views/layouts/application.html.erb +0 -13
- data/spec/support/v5.0/bin/bundle +0 -3
- data/spec/support/v5.0/bin/setup +0 -34
- data/spec/support/v5.0/bin/update +0 -29
- data/spec/support/v5.0/config/application.rb +0 -27
- data/spec/support/v5.0/config/database.yml +0 -25
- data/spec/support/v5.0/config/environments/development.rb +0 -48
- data/spec/support/v5.0/config/environments/production.rb +0 -75
- data/spec/support/v5.0/config/environments/test.rb +0 -43
- data/spec/support/v5.0/config/initializers/cookies_serializer.rb +0 -6
- data/spec/support/v5.0/config/initializers/new_framework_defaults.rb +0 -27
- data/spec/support/v5.0/config/initializers/session_store.rb +0 -4
- data/spec/support/v5.0/config/locales/en.yml +0 -23
- data/spec/support/v5.0/config/puma.rb +0 -48
- data/spec/support/v5.0/config/routes.rb +0 -5
- data/spec/support/v5.0/db/migrate/20190620000001_create_wizards.rb +0 -14
- data/spec/support/v5.0/db/migrate/20190620000002_create_wands.rb +0 -12
- data/spec/support/v5.0/db/migrate/20190620000003_create_spell_books.rb +0 -10
- data/spec/support/v5.0/db/migrate/20190620000004_add_more_column_types_to_wands.rb +0 -17
- data/spec/support/v5.0/db/migrate/20190620000005_add_broom_to_wizard.rb +0 -6
- data/spec/support/v5.0/db/migrate/20190620000006_add_more_enums_to_wizard.rb +0 -9
- data/spec/support/v5.0/db/migrate/20190620000007_add_type_to_wizard.rb +0 -6
- data/spec/support/v5.0/db/migrate/20190620000008_add_robe_to_wizard.rb +0 -8
- data/spec/support/v5.0/db/migrate/20190620000009_add_school.rb +0 -10
- data/spec/support/v5.0/db/migrate/20190620000010_add_subject.rb +0 -8
- data/spec/support/v5.0/db/migrate/20190620000011_add_subjects_wizards.rb +0 -8
- data/spec/support/v5.0/db/migrate/20190620000012_add_spell.rb +0 -8
- data/spec/support/v5.0/db/migrate/20190620000013_add_spells_spell_books.rb +0 -8
- data/spec/support/v5.0/db/schema.rb +0 -96
- data/spec/support/v5.0/public/robots.txt +0 -5
- data/spec/support/v5.1/Gemfile.lock +0 -165
- data/spec/support/v5.1/README.md +0 -24
- data/spec/support/v5.1/Rakefile +0 -6
- data/spec/support/v5.1/app/assets/config/manifest.js +0 -2
- data/spec/support/v5.1/app/controllers/application_controller.rb +0 -4
- data/spec/support/v5.1/app/helpers/application_helper.rb +0 -3
- data/spec/support/v5.1/app/helpers/bar_helper.rb +0 -3
- data/spec/support/v5.1/app/helpers/baz_helper.rb +0 -3
- data/spec/support/v5.1/app/helpers/foo_helper.rb +0 -3
- data/spec/support/v5.1/app/jobs/application_job.rb +0 -3
- data/spec/support/v5.1/app/jobs/award_house_point_hourglasses.rb +0 -12
- data/spec/support/v5.1/app/mailers/daily_prophet_mailer.rb +0 -9
- data/spec/support/v5.1/app/mailers/hogwarts_acceptance_mailer.rb +0 -29
- data/spec/support/v5.1/app/models/application_record.rb +0 -4
- data/spec/support/v5.1/app/models/concerns/.keep +0 -0
- data/spec/support/v5.1/app/models/concerns/mythical.rb +0 -11
- data/spec/support/v5.1/app/models/school.rb +0 -5
- data/spec/support/v5.1/app/models/spell_book.rb +0 -18
- data/spec/support/v5.1/app/models/squib.rb +0 -6
- data/spec/support/v5.1/app/models/wand.rb +0 -19
- data/spec/support/v5.1/app/models/wizard.rb +0 -65
- data/spec/support/v5.1/app/views/layouts/mailer.html.erb +0 -13
- data/spec/support/v5.1/app/views/layouts/mailer.text.erb +0 -1
- data/spec/support/v5.1/bin/bundle +0 -3
- data/spec/support/v5.1/bin/rails +0 -4
- data/spec/support/v5.1/bin/rake +0 -4
- data/spec/support/v5.1/bin/update +0 -29
- data/spec/support/v5.1/bin/yarn +0 -11
- data/spec/support/v5.1/config/boot.rb +0 -4
- data/spec/support/v5.1/config/environment.rb +0 -6
- data/spec/support/v5.1/config/initializers/application_controller_renderer.rb +0 -9
- data/spec/support/v5.1/config/initializers/backtrace_silencers.rb +0 -8
- data/spec/support/v5.1/config/initializers/filter_parameter_logging.rb +0 -5
- data/spec/support/v5.1/config/initializers/inflections.rb +0 -17
- data/spec/support/v5.1/config/initializers/mime_types.rb +0 -5
- data/spec/support/v5.1/config/initializers/sorbet_rails.rb +0 -3
- data/spec/support/v5.1/config/initializers/wrap_parameters.rb +0 -15
- data/spec/support/v5.1/config/routes.rb +0 -5
- data/spec/support/v5.1/config.ru +0 -5
- data/spec/support/v5.1/db/migrate/20190620000005_add_broom_to_wizard.rb +0 -6
- data/spec/support/v5.1/db/migrate/20190620000014_create_headmasters.rb +0 -9
- data/spec/support/v5.1/db/migrate/20190620000015_add_serialized_to_wizards.rb +0 -9
- data/spec/support/v5.1/db/seeds.rb +0 -8
- data/spec/support/v5.1/lib/assets/.keep +0 -0
- data/spec/support/v5.1/lib/mythical_rbi_plugin.rb +0 -16
- data/spec/support/v5.1/lib/tasks/.keep +0 -0
- data/spec/support/v5.1/log/.keep +0 -0
- data/spec/support/v5.1/package.json +0 -5
- data/spec/support/v5.1/public/robots.txt +0 -1
- data/spec/support/v5.1/sorbet_test_cases.rb +0 -409
- data/spec/support/v5.1/tmp/.keep +0 -0
- data/spec/support/v5.1/vendor/.keep +0 -0
- data/spec/test_data/v5.0/expected_active_record_base.rbi +0 -113
- data/spec/test_data/v5.0/expected_active_record_relation.rbi +0 -199
- data/spec/test_data/v5.0/expected_habtm_subjects.rbi +0 -660
- data/spec/test_data/v5.0/expected_habtm_wizards.rbi +0 -660
- data/spec/test_data/v5.0/expected_headmaster.rbi +0 -328
- data/spec/test_data/v5.0/expected_internal_metadata.rbi +0 -298
- data/spec/test_data/v5.0/expected_potion.rbi +0 -280
- data/spec/test_data/v5.0/expected_robe.rbi +0 -301
- data/spec/test_data/v5.0/expected_routes.rbi +0 -27
- data/spec/test_data/v5.0/expected_schema_migration.rbi +0 -271
- data/spec/test_data/v5.0/expected_school.rbi +0 -301
- data/spec/test_data/v5.0/expected_spell/habtm_spell_books.rbi +0 -319
- data/spec/test_data/v5.0/expected_spell.rbi +0 -292
- data/spec/test_data/v5.0/expected_spell_book/habtm_spell_books.rbi +0 -637
- data/spec/test_data/v5.0/expected_spell_book/habtm_spells.rbi +0 -319
- data/spec/test_data/v5.0/expected_spell_book.rbi +0 -415
- data/spec/test_data/v5.0/expected_squib.rbi +0 -832
- data/spec/test_data/v5.0/expected_subject/habtm_wizards.rbi +0 -319
- data/spec/test_data/v5.0/expected_subject.rbi +0 -292
- data/spec/test_data/v5.0/expected_wand.rbi +0 -497
- data/spec/test_data/v5.0/expected_wizard/habtm_subjects.rbi +0 -319
- data/spec/test_data/v5.0/expected_wizard.rbi +0 -908
- data/spec/test_data/v5.0/expected_wizard_wo_spellbook.rbi +0 -902
- data/spec/test_data/v5.1/expected_application_job.rbi +0 -20
- data/spec/test_data/v5.1/expected_application_mailer.rbi +0 -5
- data/spec/test_data/v5.1/expected_award_house_point_hourglasses.rbi +0 -20
- data/spec/test_data/v5.1/expected_custom_application_job.rbi +0 -21
- data/spec/test_data/v5.1/expected_custom_application_mailer.rbi +0 -6
- data/spec/test_data/v5.1/expected_custom_award_house_point_hourglasses.rbi +0 -21
- data/spec/test_data/v5.1/expected_custom_daily_prophet_mailer.rbi +0 -8
- data/spec/test_data/v5.1/expected_custom_hogwarts_acceptance_mailer.rbi +0 -21
- data/spec/test_data/v5.1/expected_daily_prophet_mailer.rbi +0 -7
- data/spec/test_data/v5.1/expected_helpers.rbi +0 -27
- data/spec/test_data/v5.1/expected_helpers_with_application_and_devise_helpers.rbi +0 -34
- data/spec/test_data/v5.1/expected_hogwarts_acceptance_mailer.rbi +0 -20
- data/spec/test_data/v5.1/expected_no_routes.rbi +0 -4
- data/spec/test_data/v5.1/expected_routes.rbi +0 -27
- data/spec/test_data/v5.1/expected_srb_tc_output.txt +0 -1
@@ -0,0 +1,55 @@
|
|
1
|
+
# typed: false
|
2
|
+
class AasmPlugin < SorbetRails::ModelPlugins::Base
|
3
|
+
sig { override.params(root: Parlour::RbiGenerator::Namespace).void }
|
4
|
+
def generate(root)
|
5
|
+
return unless @model_class.include?(::AASM)
|
6
|
+
|
7
|
+
model_rbi = root.create_class(
|
8
|
+
model_class_name
|
9
|
+
)
|
10
|
+
|
11
|
+
aasm_events = @model_class.aasm.events.map(&:name)
|
12
|
+
aasm_states = @model_class.aasm.states.map(&:name)
|
13
|
+
|
14
|
+
# If you have an event like :bazify, you get these methods:
|
15
|
+
# - `may_bazify?`
|
16
|
+
# - `bazify`
|
17
|
+
# - `bazify!`
|
18
|
+
# - `bazify_without_validation!`
|
19
|
+
aasm_events.each do |event|
|
20
|
+
model_rbi.create_method(
|
21
|
+
"may_#{event}?",
|
22
|
+
return_type: 'T::Boolean'
|
23
|
+
)
|
24
|
+
|
25
|
+
model_rbi.create_method(
|
26
|
+
event.to_s,
|
27
|
+
return_type: 'T::Boolean'
|
28
|
+
)
|
29
|
+
|
30
|
+
model_rbi.create_method(
|
31
|
+
"#{event}!",
|
32
|
+
return_type: 'T::Boolean'
|
33
|
+
)
|
34
|
+
|
35
|
+
model_rbi.create_method(
|
36
|
+
"#{event}_without_validation!",
|
37
|
+
return_type: 'T::Boolean'
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
# - If you have a state like :baz, you get:
|
42
|
+
# - a method `baz?`
|
43
|
+
# - a constant `STATE_BAZ`
|
44
|
+
aasm_states.each do |state|
|
45
|
+
model_rbi.create_method(
|
46
|
+
"#{state}?",
|
47
|
+
return_type: 'T::Boolean'
|
48
|
+
)
|
49
|
+
|
50
|
+
root.create_module(
|
51
|
+
"#{model_class_name}::STATE_#{state.to_s.upcase}"
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# typed: false
|
2
|
+
class AttrJsonPlugin < SorbetRails::ModelPlugins::Base
|
3
|
+
sig { override.params(root: Parlour::RbiGenerator::Namespace).void }
|
4
|
+
def generate(root)
|
5
|
+
return unless @model_class.include?(::AttrJson::Record)
|
6
|
+
|
7
|
+
# Module for instance methods
|
8
|
+
obj_custom_module_name = self.model_module_name("GeneratedAttrJsonMethods")
|
9
|
+
obj_custom_module_rbi = root.create_module(obj_custom_module_name)
|
10
|
+
|
11
|
+
# Module for class methods
|
12
|
+
klass_custom_module_name = self.model_module_name("GeneratedAttrJsonClassMethods")
|
13
|
+
klass_custom_module_rbi = root.create_module(klass_custom_module_name)
|
14
|
+
|
15
|
+
# here we re-create the model class!
|
16
|
+
model_class_rbi = root.create_class(self.model_class_name)
|
17
|
+
model_class_rbi.create_include(obj_custom_module_name)
|
18
|
+
model_class_rbi.create_extend(klass_custom_module_name)
|
19
|
+
|
20
|
+
# then create custom methods, constants, etc. for this module.
|
21
|
+
add_class_methods(klass_custom_module_rbi)
|
22
|
+
|
23
|
+
@model_class.attr_json_registry.definitions.each do |definition|
|
24
|
+
add_methods_for_attributes(definition, obj_custom_module_rbi)
|
25
|
+
end
|
26
|
+
|
27
|
+
if @model_class.include?(::AttrJson::Record::Dirty)
|
28
|
+
obj_custom_module_rbi.create_method(
|
29
|
+
'attr_json_changes',
|
30
|
+
returns: 'AttrJson::Record::Dirty::Implementation'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
sig { params(custom_module_rbi: Parlour::RbiGenerator::ModuleNamespace).void }
|
38
|
+
def add_class_methods(custom_module_rbi)
|
39
|
+
custom_module_rbi.create_method(
|
40
|
+
'attr_json_config',
|
41
|
+
parameters: [
|
42
|
+
::Parlour::RbiGenerator::Parameter.new(
|
43
|
+
'new_values',
|
44
|
+
type: 'T.nilable(T::Hash[Symbol, T.untyped])'
|
45
|
+
)
|
46
|
+
],
|
47
|
+
returns: 'T::Hash[Symbol, T.untyped]'
|
48
|
+
)
|
49
|
+
|
50
|
+
custom_module_rbi.create_method(
|
51
|
+
'attr_json',
|
52
|
+
parameters: [
|
53
|
+
::Parlour::RbiGenerator::Parameter.new(
|
54
|
+
'name',
|
55
|
+
type: 'T.any(Symbol, String)'
|
56
|
+
),
|
57
|
+
::Parlour::RbiGenerator::Parameter.new(
|
58
|
+
'type',
|
59
|
+
type: 'T.any(Symbol, ActiveModel::Type::Value)'
|
60
|
+
),
|
61
|
+
::Parlour::RbiGenerator::Parameter.new(
|
62
|
+
'**options',
|
63
|
+
type: 'T.untyped'
|
64
|
+
)
|
65
|
+
]
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
sig do
|
70
|
+
params(
|
71
|
+
definition: ::AttrJson::AttributeDefinition,
|
72
|
+
custom_module_rbi: Parlour::RbiGenerator::ModuleNamespace
|
73
|
+
)
|
74
|
+
.void
|
75
|
+
end
|
76
|
+
def add_methods_for_attributes(definition, custom_module_rbi)
|
77
|
+
# set methods can receive an argument of any type because attr_json will try
|
78
|
+
# to parse to the correct type. Example:
|
79
|
+
#
|
80
|
+
# class Post < ApplicationRecord
|
81
|
+
# ...
|
82
|
+
# attr_json :my_datetime, :datetime
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# > p = Post.new
|
86
|
+
# > (p.my_datetime = '2020-02-02').class
|
87
|
+
# => String
|
88
|
+
# > p.my_datetime.class
|
89
|
+
# => Time
|
90
|
+
#
|
91
|
+
# Also, the setter type return is the same as its argument type (before parse).
|
92
|
+
custom_module_rbi.create_method(
|
93
|
+
"#{definition.name}=",
|
94
|
+
parameters: [
|
95
|
+
::Parlour::RbiGenerator::Parameter.new(
|
96
|
+
'value',
|
97
|
+
type: 'T.untyped'
|
98
|
+
)
|
99
|
+
],
|
100
|
+
returns: 'T.untyped'
|
101
|
+
)
|
102
|
+
|
103
|
+
definition_type = get_definition_type(definition)
|
104
|
+
|
105
|
+
custom_module_rbi.create_method(
|
106
|
+
definition.name.to_s,
|
107
|
+
returns: definition_type
|
108
|
+
)
|
109
|
+
|
110
|
+
custom_module_rbi.create_method(
|
111
|
+
"#{definition.name}?",
|
112
|
+
returns: 'T::Boolean'
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
sig { params(definition: ::AttrJson::AttributeDefinition).returns(String) }
|
117
|
+
def get_definition_type(definition)
|
118
|
+
|
119
|
+
if definition.array_type?
|
120
|
+
"T::Array[#{type_to_class(definition.type.base_type.type.to_s)}]"
|
121
|
+
else
|
122
|
+
"T.nilable(#{type_to_class(definition.type.type.to_s)})"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
sig { params(type: String).returns(String) }
|
127
|
+
def type_to_class(type)
|
128
|
+
return 'T.untyped' unless type.present?
|
129
|
+
|
130
|
+
case type
|
131
|
+
when 'datetime' then 'Time'
|
132
|
+
when 'decimal' then 'BigDecimal'
|
133
|
+
when 'boolean' then 'T::Boolean'
|
134
|
+
else type.camelize
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
# typed: false
|
2
|
+
class FlagShihTzuPlugin < SorbetRails::ModelPlugins::Base
|
3
|
+
sig { override.params(root: Parlour::RbiGenerator::Namespace).void }
|
4
|
+
def generate(root)
|
5
|
+
return unless @model_class.include?(::FlagShihTzu)
|
6
|
+
|
7
|
+
obj_custom_module_name = self.model_module_name("GeneratedFlagShihTzuMethods")
|
8
|
+
obj_custom_module_rbi = root.create_module(obj_custom_module_name)
|
9
|
+
|
10
|
+
klass_custom_module_name = self.model_module_name("GeneratedFlagShihTzuClassMethods")
|
11
|
+
klass_custom_module_rbi = root.create_module(klass_custom_module_name)
|
12
|
+
|
13
|
+
|
14
|
+
# here we re-create the model class!
|
15
|
+
model_class_rbi = root.create_class(self.model_class_name)
|
16
|
+
model_class_rbi.create_include(obj_custom_module_name)
|
17
|
+
model_class_rbi.create_extend(klass_custom_module_name)
|
18
|
+
|
19
|
+
# then create custom methods, constants, etc. for this module.
|
20
|
+
add_class_methods(klass_custom_module_rbi)
|
21
|
+
|
22
|
+
if @model_class.flag_columns.present?
|
23
|
+
@model_class
|
24
|
+
.flag_columns
|
25
|
+
.each do |column|
|
26
|
+
add_methods_for_column(column, obj_custom_module_rbi)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if @model_class.flag_mapping.present?
|
31
|
+
@model_class
|
32
|
+
.flag_mapping
|
33
|
+
.each do |column, flags|
|
34
|
+
flags.keys
|
35
|
+
.select { |flag_key| really_has_the_flag?(flag_key) }
|
36
|
+
.each do |flag_key|
|
37
|
+
add_methods_for_flag(column, flag_key, obj_custom_module_rbi)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
sig { params(custom_module_rbi: Parlour::RbiGenerator::ModuleNamespace).void }
|
46
|
+
def add_class_methods(custom_module_rbi)
|
47
|
+
# https://github.com/pboling/flag_shih_tzu/blob/6a3f1c5f62bd56aa932252eef935826c9674b096/lib/flag_shih_tzu.rb#L12
|
48
|
+
custom_module_rbi.create_method(
|
49
|
+
'flag_options',
|
50
|
+
returns: 'T::Hash[String, T::Hash[Symbol, T.untyped]]'
|
51
|
+
)
|
52
|
+
|
53
|
+
# https://github.com/pboling/flag_shih_tzu/blob/6a3f1c5f62bd56aa932252eef935826c9674b096/lib/flag_shih_tzu.rb#L13
|
54
|
+
custom_module_rbi.create_method(
|
55
|
+
'flag_mapping',
|
56
|
+
returns: 'T::Hash[String, T::Hash[Symbol, Integer]]'
|
57
|
+
)
|
58
|
+
|
59
|
+
# https://github.com/pboling/flag_shih_tzu/blob/6a3f1c5f62bd56aa932252eef935826c9674b096/lib/flag_shih_tzu.rb#L14
|
60
|
+
custom_module_rbi.create_method(
|
61
|
+
'flag_columns',
|
62
|
+
returns: 'T::Array[Symbol]'
|
63
|
+
)
|
64
|
+
|
65
|
+
# https://github.com/pboling/flag_shih_tzu#updating-flag-column-by-raw-sql
|
66
|
+
custom_module_rbi.create_method(
|
67
|
+
'set_flag_sql',
|
68
|
+
parameters: [
|
69
|
+
::Parlour::RbiGenerator::Parameter.new(
|
70
|
+
'flag',
|
71
|
+
type: 'Symbol'
|
72
|
+
),
|
73
|
+
::Parlour::RbiGenerator::Parameter.new(
|
74
|
+
'value',
|
75
|
+
type: 'T::Boolean'
|
76
|
+
),
|
77
|
+
::Parlour::RbiGenerator::Parameter.new(
|
78
|
+
'colmn',
|
79
|
+
type: 'T.nilable(String)'
|
80
|
+
),
|
81
|
+
::Parlour::RbiGenerator::Parameter.new(
|
82
|
+
'custom_table_name',
|
83
|
+
type: 'T.any(String, Symbol)'
|
84
|
+
)
|
85
|
+
],
|
86
|
+
returns: 'T::Hash[String, T::Hash[Symbol, T.untyped]]'
|
87
|
+
)
|
88
|
+
|
89
|
+
if @model_class.flag_mapping.present?
|
90
|
+
# https://github.com/pboling/flag_shih_tzu#support-for-manually-building-conditions
|
91
|
+
@model_class
|
92
|
+
.flag_mapping
|
93
|
+
.flat_map { |_, flags| flags.keys }
|
94
|
+
.each do |flag_key|
|
95
|
+
next unless really_has_the_flag?(flag_key)
|
96
|
+
|
97
|
+
custom_module_rbi.create_method(
|
98
|
+
"#{flag_key}_condition",
|
99
|
+
parameters: [
|
100
|
+
::Parlour::RbiGenerator::Parameter.new(
|
101
|
+
'options',
|
102
|
+
type: 'T.nilable(T::Hash[Symbol, T.untyped])'
|
103
|
+
)
|
104
|
+
],
|
105
|
+
returns: 'String'
|
106
|
+
)
|
107
|
+
|
108
|
+
custom_module_rbi.create_method(
|
109
|
+
"not_#{flag_key}_condition",
|
110
|
+
parameters: [
|
111
|
+
::Parlour::RbiGenerator::Parameter.new(
|
112
|
+
'options',
|
113
|
+
type: 'T.nilable(T::Hash[Symbol, T.untyped])'
|
114
|
+
)
|
115
|
+
],
|
116
|
+
returns: 'String'
|
117
|
+
)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# https://github.com/pboling/flag_shih_tzu#generated-boolean-patterned-instance-methods
|
123
|
+
sig { params(column: String, custom_module_rbi: Parlour::RbiGenerator::ModuleNamespace).void }
|
124
|
+
def add_methods_for_column(column, custom_module_rbi)
|
125
|
+
custom_module_rbi.create_method(
|
126
|
+
"all_#{column}",
|
127
|
+
returns: 'T::Array[Symbol]'
|
128
|
+
)
|
129
|
+
|
130
|
+
custom_module_rbi.create_method(
|
131
|
+
"selected_#{column}",
|
132
|
+
returns: 'T::Array[Symbol]'
|
133
|
+
)
|
134
|
+
|
135
|
+
custom_module_rbi.create_method(
|
136
|
+
"select_all_#{column}",
|
137
|
+
returns: 'T::Array[Symbol]'
|
138
|
+
)
|
139
|
+
|
140
|
+
custom_module_rbi.create_method(
|
141
|
+
"unselect_all_#{column}",
|
142
|
+
returns: 'T::Array[Symbol]'
|
143
|
+
)
|
144
|
+
|
145
|
+
custom_module_rbi.create_method(
|
146
|
+
"selected_#{column}=",
|
147
|
+
parameters: [
|
148
|
+
::Parlour::RbiGenerator::Parameter.new(
|
149
|
+
'chosen_flags',
|
150
|
+
type: 'T.nilable(T::Array[Symbol])'
|
151
|
+
)
|
152
|
+
],
|
153
|
+
returns: 'T::Array[Symbol]'
|
154
|
+
)
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
# https://github.com/pboling/flag_shih_tzu#generated-boolean-patterned-instance-methods
|
159
|
+
sig { params(column: String, flag_key: Symbol, custom_module_rbi: Parlour::RbiGenerator::ModuleNamespace).void }
|
160
|
+
def add_methods_for_flag(column, flag_key, custom_module_rbi)
|
161
|
+
custom_module_rbi.create_method(flag_key.to_s, returns: 'T::Boolean')
|
162
|
+
custom_module_rbi.create_method("#{flag_key}?", returns: 'T::Boolean')
|
163
|
+
custom_module_rbi.create_method(
|
164
|
+
"#{flag_key}=",
|
165
|
+
parameters: [
|
166
|
+
::Parlour::RbiGenerator::Parameter.new(
|
167
|
+
'value',
|
168
|
+
type: 'T::Boolean'
|
169
|
+
)
|
170
|
+
],
|
171
|
+
returns: 'T::Boolean'
|
172
|
+
)
|
173
|
+
|
174
|
+
custom_module_rbi.create_method("not_#{flag_key}", returns: 'T::Boolean')
|
175
|
+
custom_module_rbi.create_method("not_#{flag_key}?", returns: 'T::Boolean')
|
176
|
+
custom_module_rbi.create_method(
|
177
|
+
"not_#{flag_key}=",
|
178
|
+
parameters: [
|
179
|
+
::Parlour::RbiGenerator::Parameter.new(
|
180
|
+
'value',
|
181
|
+
type: 'T::Boolean'
|
182
|
+
)
|
183
|
+
],
|
184
|
+
returns: 'T::Boolean'
|
185
|
+
)
|
186
|
+
|
187
|
+
custom_module_rbi.create_method("#{flag_key}_changed?", returns: 'T::Boolean')
|
188
|
+
|
189
|
+
custom_module_rbi.create_method("has_#{flag_key}?", returns: 'T::Boolean')
|
190
|
+
|
191
|
+
if @model_class.flag_options[column][:bang_methods]
|
192
|
+
custom_module_rbi.create_method("#{flag_key}!", returns: 'T::Boolean')
|
193
|
+
custom_module_rbi.create_method("not_#{flag_key}!", returns: 'T::Boolean')
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
sig { params(flag_name: Symbol).returns(T::Boolean) }
|
198
|
+
def really_has_the_flag?(flag_name)
|
199
|
+
@model_class.respond_to?("#{flag_name}_condition")
|
200
|
+
end
|
201
|
+
end
|
@@ -43,5 +43,25 @@ class KaminariPlugin < SorbetRails::ModelPlugins::Base
|
|
43
43
|
return_type: "Integer",
|
44
44
|
class_method: true,
|
45
45
|
)
|
46
|
+
|
47
|
+
# https://github.com/kaminari/kaminari/blob/c5186f5d9b7f23299d115408e62047447fd3189d/kaminari-core/lib/kaminari/models/page_scope_methods.rb#L82
|
48
|
+
model_relation_rbi = root.create_class(self.model_relation_class_name)
|
49
|
+
model_relation_rbi.create_method(
|
50
|
+
'last_page?',
|
51
|
+
parameters: nil,
|
52
|
+
return_type: 'T::Boolean',
|
53
|
+
)
|
54
|
+
model_assoc_relation_rbi = root.create_class(self.model_assoc_relation_class_name)
|
55
|
+
model_assoc_relation_rbi.create_method(
|
56
|
+
'last_page?',
|
57
|
+
parameters: nil,
|
58
|
+
return_type: 'T::Boolean',
|
59
|
+
)
|
60
|
+
collection_proxy_rbi = root.create_class(self.model_assoc_proxy_class_name)
|
61
|
+
collection_proxy_rbi.create_method(
|
62
|
+
'last_page?',
|
63
|
+
parameters: nil,
|
64
|
+
return_type: 'T::Boolean',
|
65
|
+
)
|
46
66
|
end
|
47
67
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# typed: strict
|
2
|
+
class MoneyRailsPlugin < SorbetRails::ModelPlugins::Base
|
3
|
+
sig { params(attribute: T.any(Symbol, String)).returns(T::Boolean) }
|
4
|
+
def allows_nil(attribute)
|
5
|
+
validators = model_class.validators_on(attribute)
|
6
|
+
return false if validators.empty?
|
7
|
+
|
8
|
+
validators.any? do |validator|
|
9
|
+
validator.respond_to?(:options) &&
|
10
|
+
validator.options[:allow_nil]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
sig { override.params(root: Parlour::RbiGenerator::Namespace).void }
|
15
|
+
def generate(root)
|
16
|
+
return unless exists_class_method?(:monetize)
|
17
|
+
|
18
|
+
# money-rails gives us a hash mapping the monetized attribute to its subunit
|
19
|
+
# equivalent, eg: `{"price": "price_cents"}`
|
20
|
+
monetized_attributes = T.let(
|
21
|
+
T.unsafe(model_class).monetized_attributes,
|
22
|
+
T::Hash[String,String]
|
23
|
+
)
|
24
|
+
|
25
|
+
return if monetized_attributes.empty?
|
26
|
+
|
27
|
+
module_name = model_module_name("GeneratedMoneyRailsMethods")
|
28
|
+
module_rbi = root.create_module(module_name)
|
29
|
+
|
30
|
+
model_class_rbi = root.create_class(model_class_name)
|
31
|
+
model_class_rbi.create_include(module_name)
|
32
|
+
|
33
|
+
monetized_attributes.each do |name, subunit_name|
|
34
|
+
validators = model_class.validators_on(name)
|
35
|
+
|
36
|
+
money_attribute_type = allows_nil(name) ? "T.nilable(::Money)" : "::Money"
|
37
|
+
subunit_attribute_type = allows_nil(name) ? "T.nilable(Integer)" : "Integer"
|
38
|
+
|
39
|
+
module_rbi.create_method(
|
40
|
+
name,
|
41
|
+
return_type: money_attribute_type
|
42
|
+
)
|
43
|
+
|
44
|
+
module_rbi.create_method(
|
45
|
+
subunit_name,
|
46
|
+
return_type: subunit_attribute_type
|
47
|
+
)
|
48
|
+
|
49
|
+
module_rbi.create_method(
|
50
|
+
"#{name}_money_before_type_cast",
|
51
|
+
return_type: 'T.untyped'
|
52
|
+
)
|
53
|
+
|
54
|
+
module_rbi.create_method(
|
55
|
+
"#{name}=",
|
56
|
+
parameters: [
|
57
|
+
Parlour::RbiGenerator::Parameter.new("value", type: money_attribute_type)
|
58
|
+
],
|
59
|
+
return_type: nil
|
60
|
+
)
|
61
|
+
|
62
|
+
module_rbi.create_method(
|
63
|
+
"#{subunit_name}=",
|
64
|
+
parameters: [
|
65
|
+
Parlour::RbiGenerator::Parameter.new("value", type: subunit_attribute_type)
|
66
|
+
],
|
67
|
+
return_type: nil
|
68
|
+
)
|
69
|
+
|
70
|
+
module_rbi.create_method(
|
71
|
+
"currency_for_#{name}",
|
72
|
+
return_type: "T.nilable(::Money::Currency)"
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -17,7 +17,7 @@ module SorbetRails::ModelColumnUtils
|
|
17
17
|
type = base_type.to_s
|
18
18
|
# A nullable array column should be T.nilable(T::Array[column_type]) not T::Array[T.nilable(column_type)]
|
19
19
|
type = "T::Array[#{type}]" if array_type
|
20
|
-
type = "T.nilable(#{type})" if nilable
|
20
|
+
type = "T.nilable(#{type})" if nilable && type != "T.untyped"
|
21
21
|
type
|
22
22
|
end
|
23
23
|
end
|
@@ -34,7 +34,7 @@ class SorbetRails::ModelPlugins::ActiveRecordAssoc < SorbetRails::ModelPlugins::
|
|
34
34
|
def populate_single_assoc_getter_setter(assoc_module_rbi, assoc_name, reflection)
|
35
35
|
# TODO allow people to specify the possible values of polymorphic associations
|
36
36
|
assoc_class = assoc_should_be_untyped?(reflection) ? "T.untyped" : "::#{reflection.klass.name}"
|
37
|
-
assoc_type = (belongs_to_and_required?(reflection) || has_one_and_required?(reflection)) ? assoc_class : "T.nilable(#{assoc_class})"
|
37
|
+
assoc_type = (belongs_to_and_required?(reflection) || has_one_and_required?(reflection) || assoc_class == "T.untyped") ? assoc_class : "T.nilable(#{assoc_class})"
|
38
38
|
|
39
39
|
params = [
|
40
40
|
Parameter.new("*args", type: "T.untyped"),
|
@@ -25,7 +25,8 @@ class SorbetRails::ModelPlugins::ActiveRecordQuerying < SorbetRails::ModelPlugin
|
|
25
25
|
# <Model>::Relation class.
|
26
26
|
# rails/activerecord/lib/active_record/querying.rb
|
27
27
|
model_query_relation_methods = [
|
28
|
-
:select,
|
28
|
+
# :select,
|
29
|
+
:reselect, :order, :reorder, :group, :limit, :offset, :joins, :left_joins, :left_outer_joins,
|
29
30
|
:where, :rewhere, :preload, :extract_associated, :eager_load, :includes, :from, :lock, :readonly, :or,
|
30
31
|
:having, :create_with, :distinct, :references, :none, :unscope, :optimizer_hints, :merge, :except, :only,
|
31
32
|
]
|
@@ -39,6 +40,42 @@ class SorbetRails::ModelPlugins::ActiveRecordQuerying < SorbetRails::ModelPlugin
|
|
39
40
|
builtin_query_method: true,
|
40
41
|
) if exists_class_method?(method_name)
|
41
42
|
end
|
43
|
+
if exists_class_method?("select")
|
44
|
+
# `select` can be used with a block to return an array, or with a list of column name
|
45
|
+
# to return a relation object that can be chained.
|
46
|
+
# I've seen usage of `select` with a block more often than with a list of column name.
|
47
|
+
# here we define select as taking a block, and add a `select_column` method for the other usage
|
48
|
+
add_relation_query_method(
|
49
|
+
root,
|
50
|
+
"select",
|
51
|
+
parameters: [
|
52
|
+
Parameter.new("&block", type: "T.proc.params(e: #{self.model_class_name}).returns(T::Boolean)"),
|
53
|
+
],
|
54
|
+
builtin_query_method: true,
|
55
|
+
custom_return_value: "T::Array[#{self.model_class_name}]",
|
56
|
+
)
|
57
|
+
add_relation_query_method(
|
58
|
+
root,
|
59
|
+
"select_columns", # select_column is injected by sorbet-rails
|
60
|
+
parameters: [
|
61
|
+
Parameter.new("*args", type: "T.any(String, Symbol, T::Array[T.any(String, Symbol)])"),
|
62
|
+
],
|
63
|
+
builtin_query_method: true,
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
# https://api.rubyonrails.org/v6.1.4/classes/ActiveRecord/QueryMethods/WhereChain.html#method-i-missing
|
68
|
+
# where.missing is only available in Rails 6.1 and above
|
69
|
+
if Rails.version >= "6.1"
|
70
|
+
add_relation_query_method(
|
71
|
+
root,
|
72
|
+
"where_missing", # where_missing is injected by sorbet-rails
|
73
|
+
parameters: [
|
74
|
+
Parameter.new("*args", type: "Symbol"),
|
75
|
+
],
|
76
|
+
builtin_query_method: true,
|
77
|
+
)
|
78
|
+
end
|
42
79
|
|
43
80
|
add_relation_query_method(
|
44
81
|
root,
|
@@ -60,9 +60,10 @@ class SorbetRails::ModelPlugins::ActiveRecordSerializedAttribute < SorbetRails::
|
|
60
60
|
# ActiveSupport::JSON.encode/ActiveSupport::JSON.decode
|
61
61
|
# note that Hash keys are Strings since this is JSON
|
62
62
|
'T.any(T::Array[T.untyped], T::Boolean, Float, T::Hash[String, T.untyped], Integer, String)'
|
63
|
-
|
64
|
-
# unknown uses YAML.load/YAML.dump
|
63
|
+
when 'Object', ''
|
65
64
|
'T.any(T::Array[T.untyped], T::Boolean, Float, T::Hash[T.untyped, T.untyped], Integer, String)'
|
65
|
+
else
|
66
|
+
serialization_coder.to_s
|
66
67
|
end
|
67
68
|
end
|
68
69
|
end
|
@@ -35,7 +35,14 @@ module SorbetRails::ModelPlugins
|
|
35
35
|
column_type = @model_class.type_for_attribute(column_name)
|
36
36
|
return unless column_type.is_a?(ActiveRecord::Type::Serialized)
|
37
37
|
|
38
|
-
column_type.coder.try(:object_class)
|
38
|
+
object_class = column_type.coder.try(:object_class)
|
39
|
+
if object_class
|
40
|
+
object_class
|
41
|
+
elsif column_type.coder.is_a? Class
|
42
|
+
column_type.coder
|
43
|
+
else
|
44
|
+
Object
|
45
|
+
end
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
@@ -39,7 +39,7 @@ class SorbetRails::ModelPlugins::CustomFinderMethods < SorbetRails::ModelPlugins
|
|
39
39
|
# allow common cases find_by_id
|
40
40
|
custom_module_rbi.create_method(
|
41
41
|
"find_by_id",
|
42
|
-
parameters: [ Parameter.new("id", type: "Integer") ],
|
42
|
+
parameters: [ Parameter.new("id", type: "T.nilable(Integer)") ],
|
43
43
|
return_type: "T.nilable(#{self.model_class_name})",
|
44
44
|
)
|
45
45
|
custom_module_rbi.create_method(
|
@@ -81,6 +81,18 @@ module SorbetRails::ModelPlugins
|
|
81
81
|
when :paperclip
|
82
82
|
require('sorbet-rails/gem_plugins/paperclip_plugin')
|
83
83
|
PaperclipPlugin
|
84
|
+
when :attr_json
|
85
|
+
require('sorbet-rails/gem_plugins/attr_json_plugin')
|
86
|
+
AttrJsonPlugin
|
87
|
+
when :flag_shih_tzu
|
88
|
+
require('sorbet-rails/gem_plugins/flag_shih_tzu_plugin')
|
89
|
+
FlagShihTzuPlugin
|
90
|
+
when :aasm
|
91
|
+
require('sorbet-rails/gem_plugins/aasm_plugin')
|
92
|
+
AasmPlugin
|
93
|
+
when :money_rails
|
94
|
+
require('sorbet-rails/gem_plugins/money_rails_plugin')
|
95
|
+
MoneyRailsPlugin
|
84
96
|
else
|
85
97
|
raise UnrecognizedPluginName.new(
|
86
98
|
"Unrecognized plugin with name: #{plugin_name}. Please check available plugins in the
|
@@ -28,7 +28,10 @@ class SorbetRails::ModelRbiFormatter
|
|
28
28
|
# Load all dynamic instance methods of this model by instantiating a fake model
|
29
29
|
@model_class.new unless @model_class.abstract_class?
|
30
30
|
rescue StandardError => err
|
31
|
-
puts
|
31
|
+
puts
|
32
|
+
puts "Note: Unable to create new instance of #{model_class_name}"
|
33
|
+
puts "Got a #{err.class}, with this message: #{err.message}"
|
34
|
+
puts
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
@@ -77,7 +80,7 @@ class SorbetRails::ModelRbiFormatter
|
|
77
80
|
model_relation_rbi.create_include(self.model_query_methods_returning_relation_module_name)
|
78
81
|
model_relation_rbi.create_constant(
|
79
82
|
"Elem",
|
80
|
-
value: "type_member
|
83
|
+
value: "type_member {{fixed: #{model_class_name}}}",
|
81
84
|
)
|
82
85
|
|
83
86
|
model_assoc_relation_rbi = root.create_class(
|
@@ -87,7 +90,7 @@ class SorbetRails::ModelRbiFormatter
|
|
87
90
|
model_assoc_relation_rbi.create_include(self.model_query_methods_returning_assoc_relation_module_name)
|
88
91
|
model_assoc_relation_rbi.create_constant(
|
89
92
|
"Elem",
|
90
|
-
value: "type_member
|
93
|
+
value: "type_member {{fixed: #{model_class_name}}}",
|
91
94
|
)
|
92
95
|
|
93
96
|
collection_proxy_rbi = root.create_class(
|
@@ -97,7 +100,7 @@ class SorbetRails::ModelRbiFormatter
|
|
97
100
|
collection_proxy_rbi.create_include(self.model_query_methods_returning_assoc_relation_module_name)
|
98
101
|
collection_proxy_rbi.create_constant(
|
99
102
|
"Elem",
|
100
|
-
value: "type_member
|
103
|
+
value: "type_member {{fixed: #{self.model_class_name}}}",
|
101
104
|
)
|
102
105
|
|
103
106
|
model_rbi = root.create_class(
|