omg-railties 8.0.0.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +171 -0
- data/MIT-LICENSE +20 -0
- data/RDOC_MAIN.md +99 -0
- data/README.rdoc +39 -0
- data/exe/rails +10 -0
- data/lib/minitest/rails_plugin.rb +140 -0
- data/lib/rails/all.rb +21 -0
- data/lib/rails/api/generator.rb +38 -0
- data/lib/rails/api/task.rb +235 -0
- data/lib/rails/app_loader.rb +77 -0
- data/lib/rails/application/bootstrap.rb +118 -0
- data/lib/rails/application/configuration.rb +659 -0
- data/lib/rails/application/default_middleware_stack.rb +140 -0
- data/lib/rails/application/dummy_config.rb +19 -0
- data/lib/rails/application/finisher.rb +238 -0
- data/lib/rails/application/routes_reloader.rb +79 -0
- data/lib/rails/application.rb +658 -0
- data/lib/rails/application_controller.rb +28 -0
- data/lib/rails/autoloaders/inflector.rb +21 -0
- data/lib/rails/autoloaders.rb +48 -0
- data/lib/rails/backtrace_cleaner.rb +42 -0
- data/lib/rails/cli.rb +21 -0
- data/lib/rails/code_statistics.rb +159 -0
- data/lib/rails/code_statistics_calculator.rb +99 -0
- data/lib/rails/command/actions.rb +52 -0
- data/lib/rails/command/base.rb +185 -0
- data/lib/rails/command/behavior.rb +84 -0
- data/lib/rails/command/environment_argument.rb +56 -0
- data/lib/rails/command/helpers/editor.rb +40 -0
- data/lib/rails/command.rb +172 -0
- data/lib/rails/commands/about/about_command.rb +14 -0
- data/lib/rails/commands/app/update_command.rb +94 -0
- data/lib/rails/commands/application/application_command.rb +33 -0
- data/lib/rails/commands/boot/boot_command.rb +14 -0
- data/lib/rails/commands/console/console_command.rb +91 -0
- data/lib/rails/commands/console/irb_console.rb +136 -0
- data/lib/rails/commands/credentials/USAGE +73 -0
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +53 -0
- data/lib/rails/commands/credentials/credentials_command.rb +139 -0
- data/lib/rails/commands/db/system/change/change_command.rb +26 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +88 -0
- data/lib/rails/commands/destroy/destroy_command.rb +29 -0
- data/lib/rails/commands/dev/dev_command.rb +14 -0
- data/lib/rails/commands/devcontainer/devcontainer_command.rb +39 -0
- data/lib/rails/commands/encrypted/USAGE +23 -0
- data/lib/rails/commands/encrypted/encrypted_command.rb +98 -0
- data/lib/rails/commands/gem_help/USAGE +16 -0
- data/lib/rails/commands/gem_help/gem_help_command.rb +13 -0
- data/lib/rails/commands/generate/generate_command.rb +30 -0
- data/lib/rails/commands/help/USAGE +17 -0
- data/lib/rails/commands/help/help_command.rb +34 -0
- data/lib/rails/commands/initializers/initializers_command.rb +20 -0
- data/lib/rails/commands/middleware/middleware_command.rb +17 -0
- data/lib/rails/commands/new/new_command.rb +21 -0
- data/lib/rails/commands/notes/notes_command.rb +30 -0
- data/lib/rails/commands/plugin/plugin_command.rb +47 -0
- data/lib/rails/commands/rake/rake_command.rb +55 -0
- data/lib/rails/commands/restart/restart_command.rb +14 -0
- data/lib/rails/commands/routes/routes_command.rb +49 -0
- data/lib/rails/commands/runner/USAGE +22 -0
- data/lib/rails/commands/runner/runner_command.rb +81 -0
- data/lib/rails/commands/secret/secret_command.rb +13 -0
- data/lib/rails/commands/server/server_command.rb +290 -0
- data/lib/rails/commands/stats/stats_command.rb +19 -0
- data/lib/rails/commands/test/USAGE +14 -0
- data/lib/rails/commands/test/test_command.rb +81 -0
- data/lib/rails/commands/unused_routes/unused_routes_command.rb +75 -0
- data/lib/rails/commands/version/version_command.rb +12 -0
- data/lib/rails/commands.rb +18 -0
- data/lib/rails/configuration.rb +170 -0
- data/lib/rails/console/app.rb +8 -0
- data/lib/rails/console/helpers.rb +8 -0
- data/lib/rails/console/methods.rb +23 -0
- data/lib/rails/deprecator.rb +7 -0
- data/lib/rails/dev_caching.rb +44 -0
- data/lib/rails/engine/commands.rb +9 -0
- data/lib/rails/engine/configuration.rb +138 -0
- data/lib/rails/engine/lazy_route_set.rb +109 -0
- data/lib/rails/engine/railties.rb +23 -0
- data/lib/rails/engine/updater.rb +21 -0
- data/lib/rails/engine.rb +760 -0
- data/lib/rails/gem_version.rb +17 -0
- data/lib/rails/generators/actions/create_migration.rb +75 -0
- data/lib/rails/generators/actions.rb +528 -0
- data/lib/rails/generators/active_model.rb +94 -0
- data/lib/rails/generators/app_base.rb +806 -0
- data/lib/rails/generators/app_name.rb +39 -0
- data/lib/rails/generators/base.rb +432 -0
- data/lib/rails/generators/database.rb +287 -0
- data/lib/rails/generators/erb/authentication/authentication_generator.rb +15 -0
- data/lib/rails/generators/erb/authentication/templates/views/passwords/edit.html.erb +9 -0
- data/lib/rails/generators/erb/authentication/templates/views/passwords/new.html.erb +8 -0
- data/lib/rails/generators/erb/authentication/templates/views/sessions/new.html.erb +11 -0
- data/lib/rails/generators/erb/controller/controller_generator.rb +24 -0
- data/lib/rails/generators/erb/controller/templates/view.html.erb.tt +2 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +41 -0
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +13 -0
- data/lib/rails/generators/erb/mailer/templates/layout.text.erb.tt +1 -0
- data/lib/rails/generators/erb/mailer/templates/view.html.erb.tt +5 -0
- data/lib/rails/generators/erb/mailer/templates/view.text.erb.tt +3 -0
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +34 -0
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +37 -0
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +12 -0
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +16 -0
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +11 -0
- data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +17 -0
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +10 -0
- data/lib/rails/generators/erb.rb +26 -0
- data/lib/rails/generators/generated_attribute.rb +274 -0
- data/lib/rails/generators/migration.rb +71 -0
- data/lib/rails/generators/model_helpers.rb +62 -0
- data/lib/rails/generators/named_base.rb +227 -0
- data/lib/rails/generators/rails/app/USAGE +31 -0
- data/lib/rails/generators/rails/app/app_generator.rb +678 -0
- data/lib/rails/generators/rails/app/templates/Dockerfile.tt +119 -0
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +83 -0
- data/lib/rails/generators/rails/app/templates/README.md.tt +24 -0
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +6 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +15 -0
- data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +6 -0
- data/lib/rails/generators/rails/app/templates/app/helpers/application_helper.rb.tt +2 -0
- data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +7 -0
- data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +4 -0
- data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +3 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +33 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +13 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.text.erb.tt +1 -0
- data/lib/rails/generators/rails/app/templates/app/views/pwa/manifest.json.erb.tt +22 -0
- data/lib/rails/generators/rails/app/templates/app/views/pwa/service-worker.js +26 -0
- data/lib/rails/generators/rails/app/templates/bin/brakeman.tt +6 -0
- data/lib/rails/generators/rails/app/templates/bin/dev.tt +1 -0
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +3 -0
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +3 -0
- data/lib/rails/generators/rails/app/templates/bin/rubocop.tt +7 -0
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +45 -0
- data/lib/rails/generators/rails/app/templates/bin/thrust.tt +4 -0
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +42 -0
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +6 -0
- data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +10 -0
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +82 -0
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +114 -0
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +72 -0
- data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +82 -0
- data/lib/rails/generators/rails/app/templates/config/deploy.yml.tt +107 -0
- data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +5 -0
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +89 -0
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +125 -0
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +62 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +7 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +25 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +16 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +8 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb.tt +16 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_8_0.rb.tt +25 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +31 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +43 -0
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +16 -0
- data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +34 -0
- data/lib/rails/generators/rails/app/templates/config.ru.tt +6 -0
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +9 -0
- data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +16 -0
- data/lib/rails/generators/rails/app/templates/dockerignore.tt +56 -0
- data/lib/rails/generators/rails/app/templates/env.erb.tt +5 -0
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +9 -0
- data/lib/rails/generators/rails/app/templates/github/ci.yml.tt +138 -0
- data/lib/rails/generators/rails/app/templates/github/dependabot.yml +12 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +38 -0
- data/lib/rails/generators/rails/app/templates/node-version.tt +1 -0
- data/lib/rails/generators/rails/app/templates/public/400.html +67 -0
- data/lib/rails/generators/rails/app/templates/public/404.html +67 -0
- data/lib/rails/generators/rails/app/templates/public/406-unsupported-browser.html +66 -0
- data/lib/rails/generators/rails/app/templates/public/422.html +67 -0
- data/lib/rails/generators/rails/app/templates/public/500.html +66 -0
- data/lib/rails/generators/rails/app/templates/public/icon.png +0 -0
- data/lib/rails/generators/rails/app/templates/public/icon.svg +3 -0
- data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -0
- data/lib/rails/generators/rails/app/templates/rubocop.yml.tt +8 -0
- data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -0
- data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb.tt +5 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +21 -0
- data/lib/rails/generators/rails/application_record/application_record_generator.rb +13 -0
- data/lib/rails/generators/rails/authentication/USAGE +6 -0
- data/lib/rails/generators/rails/authentication/authentication_generator.rb +54 -0
- data/lib/rails/generators/rails/authentication/templates/controllers/concerns/authentication.rb +55 -0
- data/lib/rails/generators/rails/authentication/templates/controllers/passwords_controller.rb +33 -0
- data/lib/rails/generators/rails/authentication/templates/controllers/sessions_controller.rb +21 -0
- data/lib/rails/generators/rails/authentication/templates/mailers/passwords_mailer.rb +6 -0
- data/lib/rails/generators/rails/authentication/templates/models/current.rb +4 -0
- data/lib/rails/generators/rails/authentication/templates/models/session.rb +3 -0
- data/lib/rails/generators/rails/authentication/templates/models/user.rb +6 -0
- data/lib/rails/generators/rails/authentication/templates/test/mailers/previews/passwords_mailer_preview.rb +7 -0
- data/lib/rails/generators/rails/authentication/templates/views/passwords_mailer/reset.html.erb +4 -0
- data/lib/rails/generators/rails/authentication/templates/views/passwords_mailer/reset.text.erb +2 -0
- data/lib/rails/generators/rails/benchmark/USAGE +19 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +30 -0
- data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
- data/lib/rails/generators/rails/controller/USAGE +26 -0
- data/lib/rails/generators/rails/controller/controller_generator.rb +42 -0
- data/lib/rails/generators/rails/controller/templates/controller.rb.tt +9 -0
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +61 -0
- data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +12 -0
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +206 -0
- data/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb +168 -0
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/Dockerfile.tt +3 -0
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/compose.yaml.tt +47 -0
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/devcontainer.json.tt +37 -0
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +31 -0
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +57 -0
- data/lib/rails/generators/rails/generator/USAGE +13 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +27 -0
- data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +3 -0
- data/lib/rails/generators/rails/generator/templates/USAGE.tt +8 -0
- data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
- data/lib/rails/generators/rails/helper/USAGE +12 -0
- data/lib/rails/generators/rails/helper/helper_generator.rb +20 -0
- data/lib/rails/generators/rails/helper/templates/helper.rb.tt +4 -0
- data/lib/rails/generators/rails/integration_test/USAGE +10 -0
- data/lib/rails/generators/rails/integration_test/integration_test_generator.rb +9 -0
- data/lib/rails/generators/rails/master_key/master_key_generator.rb +53 -0
- data/lib/rails/generators/rails/migration/USAGE +45 -0
- data/lib/rails/generators/rails/migration/migration_generator.rb +14 -0
- data/lib/rails/generators/rails/model/model_generator.rb +18 -0
- data/lib/rails/generators/rails/plugin/USAGE +21 -0
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +499 -0
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +28 -0
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +23 -0
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +20 -0
- data/lib/rails/generators/rails/plugin/templates/README.md.tt +28 -0
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +14 -0
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +7 -0
- data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +6 -0
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +17 -0
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +15 -0
- data/lib/rails/generators/rails/plugin/templates/bin/rubocop.tt +7 -0
- data/lib/rails/generators/rails/plugin/templates/bin/test.tt +4 -0
- data/lib/rails/generators/rails/plugin/templates/config/routes.rb.tt +6 -0
- data/lib/rails/generators/rails/plugin/templates/github/ci.yml.tt +103 -0
- data/lib/rails/generators/rails/plugin/templates/github/dependabot.yml +12 -0
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +14 -0
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +7 -0
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +8 -0
- data/lib/rails/generators/rails/plugin/templates/lib/tasks/%namespaced_name%_tasks.rake.tt +4 -0
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/rails/routes.rb.tt +3 -0
- data/lib/rails/generators/rails/plugin/templates/rails/stylesheets.css +15 -0
- data/lib/rails/generators/rails/plugin/templates/rubocop.yml.tt +8 -0
- data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +7 -0
- data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb.tt +5 -0
- data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +7 -0
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +21 -0
- data/lib/rails/generators/rails/resource/USAGE +23 -0
- data/lib/rails/generators/rails/resource/resource_generator.rb +27 -0
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +23 -0
- data/lib/rails/generators/rails/scaffold/USAGE +41 -0
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +18 -0
- data/lib/rails/generators/rails/scaffold_controller/USAGE +19 -0
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +56 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +57 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +64 -0
- data/lib/rails/generators/rails/script/USAGE +18 -0
- data/lib/rails/generators/rails/script/script_generator.rb +18 -0
- data/lib/rails/generators/rails/script/templates/script.rb.tt +3 -0
- data/lib/rails/generators/rails/system_test/USAGE +10 -0
- data/lib/rails/generators/rails/system_test/system_test_generator.rb +9 -0
- data/lib/rails/generators/rails/task/USAGE +9 -0
- data/lib/rails/generators/rails/task/task_generator.rb +13 -0
- data/lib/rails/generators/rails/task/templates/task.rb.tt +8 -0
- data/lib/rails/generators/resource_helpers.rb +82 -0
- data/lib/rails/generators/test_case.rb +37 -0
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +19 -0
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +23 -0
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +27 -0
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +16 -0
- data/lib/rails/generators/test_unit/helper/helper_generator.rb +11 -0
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +20 -0
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +9 -0
- data/lib/rails/generators/test_unit/job/job_generator.rb +20 -0
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +9 -0
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +28 -0
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +23 -0
- data/lib/rails/generators/test_unit/mailer/templates/preview.rb.tt +14 -0
- data/lib/rails/generators/test_unit/model/model_generator.rb +37 -0
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +29 -0
- data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +9 -0
- data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +15 -0
- data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +7 -0
- data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -0
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +82 -0
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +44 -0
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +54 -0
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +57 -0
- data/lib/rails/generators/test_unit/system/system_generator.rb +24 -0
- data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb.tt +5 -0
- data/lib/rails/generators/test_unit/system/templates/system_test.rb.tt +9 -0
- data/lib/rails/generators/test_unit.rb +10 -0
- data/lib/rails/generators/testing/assertions.rb +147 -0
- data/lib/rails/generators/testing/behavior.rb +116 -0
- data/lib/rails/generators/testing/setup_and_teardown.rb +20 -0
- data/lib/rails/generators.rb +327 -0
- data/lib/rails/health_controller.rb +55 -0
- data/lib/rails/info.rb +105 -0
- data/lib/rails/info_controller.rb +71 -0
- data/lib/rails/initializable.rb +95 -0
- data/lib/rails/mailers_controller.rb +122 -0
- data/lib/rails/paths.rb +246 -0
- data/lib/rails/plugin/test.rb +9 -0
- data/lib/rails/pwa_controller.rb +15 -0
- data/lib/rails/rack/logger.rb +88 -0
- data/lib/rails/rack/silence_request.rb +33 -0
- data/lib/rails/rack.rb +8 -0
- data/lib/rails/rackup/server.rb +15 -0
- data/lib/rails/railtie/configurable.rb +36 -0
- data/lib/rails/railtie/configuration.rb +114 -0
- data/lib/rails/railtie.rb +302 -0
- data/lib/rails/source_annotation_extractor.rb +214 -0
- data/lib/rails/tasks/engine.rake +85 -0
- data/lib/rails/tasks/framework.rake +34 -0
- data/lib/rails/tasks/log.rake +41 -0
- data/lib/rails/tasks/misc.rake +68 -0
- data/lib/rails/tasks/statistics.rake +23 -0
- data/lib/rails/tasks/tmp.rake +51 -0
- data/lib/rails/tasks/yarn.rake +29 -0
- data/lib/rails/tasks/zeitwerk.rake +41 -0
- data/lib/rails/tasks.rb +17 -0
- data/lib/rails/templates/layouts/application.html.erb +51 -0
- data/lib/rails/templates/rails/info/notes.html.erb +65 -0
- data/lib/rails/templates/rails/info/properties.html.erb +1 -0
- data/lib/rails/templates/rails/info/routes.html.erb +9 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +201 -0
- data/lib/rails/templates/rails/mailers/index.html.erb +15 -0
- data/lib/rails/templates/rails/mailers/mailer.html.erb +12 -0
- data/lib/rails/templates/rails/welcome/index.html.erb +93 -0
- data/lib/rails/test_help.rb +47 -0
- data/lib/rails/test_unit/line_filtering.rb +13 -0
- data/lib/rails/test_unit/railtie.rb +25 -0
- data/lib/rails/test_unit/reporter.rb +121 -0
- data/lib/rails/test_unit/runner.rb +209 -0
- data/lib/rails/test_unit/test_parser.rb +133 -0
- data/lib/rails/test_unit/testing.rake +39 -0
- data/lib/rails/testing/maintain_test_schema.rb +16 -0
- data/lib/rails/version.rb +10 -0
- data/lib/rails/welcome_controller.rb +11 -0
- data/lib/rails/zeitwerk_checker.rb +15 -0
- data/lib/rails.rb +130 -0
- metadata +518 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Your browser is not supported (406)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
.rails-default-error-page {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rails-default-error-page div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
.rails-default-error-page h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body class="rails-default-error-page">
|
58
|
+
<!-- This file lives in public/406-unsupported-browser.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>Your browser is not supported.</h1>
|
62
|
+
<p>Please upgrade your browser to continue.</p>
|
63
|
+
</div>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
.rails-default-error-page {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rails-default-error-page div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
.rails-default-error-page h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body class="rails-default-error-page">
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
.rails-default-error-page {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rails-default-error-page div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
.rails-default-error-page h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body class="rails-default-error-page">
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= ENV["RBENV_VERSION"] || ENV["rvm_ruby_string"] || "#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}" %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= "test"
|
2
|
+
require_relative "../config/environment"
|
3
|
+
require "rails/test_help"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
class TestCase
|
7
|
+
# Run tests in parallel with specified workers
|
8
|
+
<% if Process.respond_to?(:fork) && !Gem.win_platform? -%>
|
9
|
+
parallelize(workers: :number_of_processors)
|
10
|
+
<%- else -%>
|
11
|
+
parallelize(workers: :number_of_processors, with: :threads)
|
12
|
+
<% end -%>
|
13
|
+
|
14
|
+
<% unless options[:skip_active_record] -%>
|
15
|
+
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
16
|
+
fixtures :all
|
17
|
+
|
18
|
+
<% end -%>
|
19
|
+
# Add more helper methods to be used by all tests here...
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
class ApplicationRecordGenerator < Base # :nodoc:
|
6
|
+
hook_for :orm, required: true, desc: "ORM to be invoked"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
delegate(:desc, to: :orm_generator)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
class AuthenticationGenerator < Base # :nodoc:
|
6
|
+
class_option :api, type: :boolean,
|
7
|
+
desc: "Generate API-only controllers and models, with no view templates"
|
8
|
+
|
9
|
+
hook_for :template_engine, as: :authentication do |template_engine|
|
10
|
+
invoke template_engine unless options.api?
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_authentication_files
|
14
|
+
template "models/session.rb", File.join("app/models/session.rb")
|
15
|
+
template "models/user.rb", File.join("app/models/user.rb")
|
16
|
+
template "models/current.rb", File.join("app/models/current.rb")
|
17
|
+
|
18
|
+
template "controllers/sessions_controller.rb", File.join("app/controllers/sessions_controller.rb")
|
19
|
+
template "controllers/concerns/authentication.rb", File.join("app/controllers/concerns/authentication.rb")
|
20
|
+
template "controllers/passwords_controller.rb", File.join("app/controllers/passwords_controller.rb")
|
21
|
+
|
22
|
+
template "mailers/passwords_mailer.rb", File.join("app/mailers/passwords_mailer.rb")
|
23
|
+
|
24
|
+
template "views/passwords_mailer/reset.html.erb", File.join("app/views/passwords_mailer/reset.html.erb")
|
25
|
+
template "views/passwords_mailer/reset.text.erb", File.join("app/views/passwords_mailer/reset.text.erb")
|
26
|
+
|
27
|
+
template "test/mailers/previews/passwords_mailer_preview.rb", File.join("test/mailers/previews/passwords_mailer_preview.rb")
|
28
|
+
end
|
29
|
+
|
30
|
+
def configure_application_controller
|
31
|
+
gsub_file "app/controllers/application_controller.rb", /(class ApplicationController < ActionController::Base)/, "\\1\n include Authentication"
|
32
|
+
end
|
33
|
+
|
34
|
+
def configure_authentication_routes
|
35
|
+
route "resources :passwords, param: :token"
|
36
|
+
route "resource :session"
|
37
|
+
end
|
38
|
+
|
39
|
+
def enable_bcrypt
|
40
|
+
if File.read("Gemfile").include?('gem "bcrypt"')
|
41
|
+
uncomment_lines "Gemfile", /gem "bcrypt"/
|
42
|
+
Bundler.with_original_env { execute_command :bundle, "install --quiet" }
|
43
|
+
else
|
44
|
+
Bundler.with_original_env { execute_command :bundle, "add bcrypt --quiet" }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_migrations
|
49
|
+
generate "migration CreateUsers email_address:string!:uniq password_digest:string! --force"
|
50
|
+
generate "migration CreateSessions user:references ip_address:string user_agent:string --force"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/rails/generators/rails/authentication/templates/controllers/concerns/authentication.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Authentication
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
before_action :require_authentication
|
6
|
+
helper_method :authenticated?
|
7
|
+
end
|
8
|
+
|
9
|
+
class_methods do
|
10
|
+
def allow_unauthenticated_access(**options)
|
11
|
+
skip_before_action :require_authentication, **options
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def authenticated?
|
17
|
+
Current.session.present?
|
18
|
+
end
|
19
|
+
|
20
|
+
def require_authentication
|
21
|
+
resume_session || request_authentication
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def resume_session
|
26
|
+
Current.session = find_session_by_cookie
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_session_by_cookie
|
30
|
+
Session.find_by(id: cookies.signed[:session_id])
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def request_authentication
|
35
|
+
session[:return_to_after_authenticating] = request.url
|
36
|
+
redirect_to new_session_url
|
37
|
+
end
|
38
|
+
|
39
|
+
def after_authentication_url
|
40
|
+
session.delete(:return_to_after_authenticating) || root_url
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def start_new_session_for(user)
|
45
|
+
user.sessions.create!(user_agent: request.user_agent, ip_address: request.remote_ip).tap do |session|
|
46
|
+
Current.session = session
|
47
|
+
cookies.signed.permanent[:session_id] = { value: session.id, httponly: true, same_site: :lax }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def terminate_session
|
52
|
+
Current.session.destroy
|
53
|
+
cookies.delete(:session_id)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class PasswordsController < ApplicationController
|
2
|
+
allow_unauthenticated_access
|
3
|
+
before_action :set_user_by_token, only: %i[ edit update ]
|
4
|
+
|
5
|
+
def new
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
if user = User.find_by(email_address: params[:email_address])
|
10
|
+
PasswordsMailer.reset(user).deliver_later
|
11
|
+
end
|
12
|
+
|
13
|
+
redirect_to new_session_url, notice: "Password reset instructions sent (if user with that email address exists)."
|
14
|
+
end
|
15
|
+
|
16
|
+
def edit
|
17
|
+
end
|
18
|
+
|
19
|
+
def update
|
20
|
+
if @user.update(params.permit(:password, :password_confirmation))
|
21
|
+
redirect_to new_session_url, notice: "Password has been reset."
|
22
|
+
else
|
23
|
+
redirect_to edit_password_url(params[:token]), alert: "Passwords did not match."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def set_user_by_token
|
29
|
+
@user = User.find_by_password_reset_token!(params[:token])
|
30
|
+
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
31
|
+
redirect_to new_password_url, alert: "Password reset link is invalid or has expired."
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class SessionsController < ApplicationController
|
2
|
+
allow_unauthenticated_access only: %i[ new create ]
|
3
|
+
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." }
|
4
|
+
|
5
|
+
def new
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
if user = User.authenticate_by(params.permit(:email_address, :password))
|
10
|
+
start_new_session_for user
|
11
|
+
redirect_to after_authentication_url
|
12
|
+
else
|
13
|
+
redirect_to new_session_url, alert: "Try another email address or password."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
terminate_session
|
19
|
+
redirect_to new_session_url
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Preview all emails at http://localhost:3000/rails/mailers/passwords_mailer
|
2
|
+
class PasswordsMailerPreview < ActionMailer::Preview
|
3
|
+
# Preview this email at http://localhost:3000/rails/mailers/passwords_mailer/reset
|
4
|
+
def reset
|
5
|
+
PasswordsMailer.reset(User.take)
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Description:
|
2
|
+
Generate benchmarks to compare performance optimizations.
|
3
|
+
|
4
|
+
Makes use of the `benchmark-ips` gem as it provides a number of benefits like:
|
5
|
+
- Simple significance test
|
6
|
+
- Automatic warmup
|
7
|
+
- No need to specify the number of iterations
|
8
|
+
|
9
|
+
Example:
|
10
|
+
`bin/rails generate benchmark opt_compare`
|
11
|
+
|
12
|
+
This will create:
|
13
|
+
script/benchmarks/opt_compare.rb
|
14
|
+
|
15
|
+
You can run the generated benchmark file using:
|
16
|
+
`ruby script/benchmarks/opt_compare.rb`
|
17
|
+
|
18
|
+
You can specify different reports:
|
19
|
+
`bin/rails generate benchmark opt_compare patch1 patch2 patch3`
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators/named_base"
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
module Generators
|
7
|
+
class BenchmarkGenerator < NamedBase
|
8
|
+
IPS_GEM_NAME = "benchmark-ips"
|
9
|
+
IPS_GEM_USED_REGEXP = /gem.*\b#{IPS_GEM_NAME}\b.*/
|
10
|
+
|
11
|
+
argument :reports, type: :array, default: ["before", "after"]
|
12
|
+
|
13
|
+
def generate_layout
|
14
|
+
add_ips_to_gemfile unless ips_installed?
|
15
|
+
template("benchmark.rb.tt", "script/benchmarks/#{file_name}.rb")
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def add_ips_to_gemfile
|
20
|
+
gem(IPS_GEM_NAME, group: [:development, :test])
|
21
|
+
end
|
22
|
+
|
23
|
+
def ips_installed?
|
24
|
+
in_root do
|
25
|
+
return File.read("Gemfile").match?(IPS_GEM_USED_REGEXP)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../config/environment"
|
4
|
+
|
5
|
+
# Any benchmarking setup goes here...
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
Benchmark.ips do |x|
|
10
|
+
<%- reports.each do |report| -%>
|
11
|
+
x.report("<%= report %>") { }
|
12
|
+
<%- end -%>
|
13
|
+
|
14
|
+
x.compare!
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Description:
|
2
|
+
Generates a new controller and its views. Pass the controller name, either
|
3
|
+
CamelCased or under_scored, and a list of actions as arguments.
|
4
|
+
|
5
|
+
To create a controller within a module, specify the controller name as a
|
6
|
+
path like 'parent_module/controller_name'.
|
7
|
+
|
8
|
+
This generates a controller class in app/controllers and invokes helper,
|
9
|
+
template engine, assets, and test framework generators.
|
10
|
+
|
11
|
+
Examples:
|
12
|
+
`bin/rails generate controller credit_cards open debit credit close`
|
13
|
+
|
14
|
+
This generates a `CreditCardsController` with routes like /credit_cards/debit.
|
15
|
+
Controller: app/controllers/credit_cards_controller.rb
|
16
|
+
Test: test/controllers/credit_cards_controller_test.rb
|
17
|
+
Views: app/views/credit_cards/debit.html.erb [...]
|
18
|
+
Helper: app/helpers/credit_cards_helper.rb
|
19
|
+
|
20
|
+
`bin/rails generate controller users index --skip-routes`
|
21
|
+
|
22
|
+
This generates a `UsersController` with an index action and no routes.
|
23
|
+
|
24
|
+
`bin/rails generate controller admin/dashboard --parent=admin_controller`
|
25
|
+
|
26
|
+
This generates a `Admin::DashboardController` with an `AdminController` parent class.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
class ControllerGenerator < NamedBase # :nodoc:
|
6
|
+
argument :actions, type: :array, default: [], banner: "action action"
|
7
|
+
class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
|
8
|
+
class_option :helper, type: :boolean
|
9
|
+
class_option :parent, type: :string, default: "ApplicationController", desc: "The parent class for the generated controller"
|
10
|
+
|
11
|
+
check_class_collision suffix: "Controller"
|
12
|
+
|
13
|
+
def create_controller_files
|
14
|
+
template "controller.rb", File.join("app/controllers", class_path, "#{file_name}_controller.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_routes
|
18
|
+
return if options[:skip_routes]
|
19
|
+
return if actions.empty?
|
20
|
+
routing_code = actions.map { |action| %(get "#{file_name}/#{action}") }.join("\n")
|
21
|
+
route routing_code, namespace: regular_class_path
|
22
|
+
end
|
23
|
+
|
24
|
+
hook_for :template_engine, :test_framework, :helper do |generator|
|
25
|
+
invoke generator, [ remove_possible_suffix(name), actions ]
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def parent_class_name
|
30
|
+
options[:parent]
|
31
|
+
end
|
32
|
+
|
33
|
+
def file_name
|
34
|
+
@_file_name ||= remove_possible_suffix(super)
|
35
|
+
end
|
36
|
+
|
37
|
+
def remove_possible_suffix(name)
|
38
|
+
name.sub(/_?controller$/i, "")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|