railties 5.1.7 → 5.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +77 -241
- data/RDOC_MAIN.rdoc +61 -43
- data/README.rdoc +1 -2
- data/exe/rails +3 -2
- data/lib/minitest/rails_plugin.rb +9 -13
- data/lib/rails.rb +4 -2
- data/lib/rails/all.rb +3 -0
- data/lib/rails/api/generator.rb +10 -1
- data/lib/rails/api/task.rb +11 -1
- data/lib/rails/app_loader.rb +18 -5
- data/lib/rails/app_updater.rb +34 -0
- data/lib/rails/application.rb +90 -18
- data/lib/rails/application/bootstrap.rb +2 -0
- data/lib/rails/application/configuration.rb +79 -36
- data/lib/rails/application/default_middleware_stack.rb +7 -1
- data/lib/rails/application/finisher.rb +3 -1
- data/lib/rails/application/routes_reloader.rb +21 -3
- data/lib/rails/application_controller.rb +3 -1
- data/lib/rails/backtrace_cleaner.rb +3 -1
- data/lib/rails/cli.rb +2 -0
- data/lib/rails/code_statistics.rb +2 -0
- data/lib/rails/code_statistics_calculator.rb +2 -0
- data/lib/rails/command.rb +3 -1
- data/lib/rails/command/actions.rb +6 -4
- data/lib/rails/command/base.rb +5 -3
- data/lib/rails/command/behavior.rb +2 -0
- data/lib/rails/command/environment_argument.rb +14 -1
- data/lib/rails/command/helpers/editor.rb +35 -0
- data/lib/rails/commands.rb +2 -0
- data/lib/rails/commands/application/application_command.rb +2 -0
- data/lib/rails/commands/console/console_command.rb +2 -3
- data/lib/rails/commands/credentials/USAGE +40 -0
- data/lib/rails/commands/credentials/credentials_command.rb +72 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +18 -7
- data/lib/rails/commands/destroy/destroy_command.rb +2 -0
- data/lib/rails/commands/encrypted/encrypted_command.rb +77 -0
- data/lib/rails/commands/generate/generate_command.rb +2 -0
- data/lib/rails/commands/help/help_command.rb +2 -0
- data/lib/rails/commands/new/new_command.rb +2 -0
- data/lib/rails/commands/plugin/plugin_command.rb +2 -0
- data/lib/rails/commands/rake/rake_command.rb +2 -0
- data/lib/rails/commands/runner/USAGE +3 -0
- data/lib/rails/commands/runner/runner_command.rb +7 -3
- data/lib/rails/commands/secrets/secrets_command.rb +15 -10
- data/lib/rails/commands/server/server_command.rb +24 -3
- data/lib/rails/commands/test/test_command.rb +18 -23
- data/lib/rails/commands/version/version_command.rb +2 -0
- data/lib/rails/configuration.rb +2 -0
- data/lib/rails/console/app.rb +2 -0
- data/lib/rails/console/helpers.rb +2 -0
- data/lib/rails/dev_caching.rb +2 -1
- data/lib/rails/engine.rb +3 -1
- data/lib/rails/engine/commands.rb +2 -0
- data/lib/rails/engine/configuration.rb +2 -0
- data/lib/rails/engine/railties.rb +2 -0
- data/lib/rails/engine/updater.rb +3 -1
- data/lib/rails/gem_version.rb +5 -3
- data/lib/rails/generators.rb +8 -3
- data/lib/rails/generators/actions.rb +53 -24
- data/lib/rails/generators/actions/create_migration.rb +2 -0
- data/lib/rails/generators/active_model.rb +2 -0
- data/lib/rails/generators/app_base.rb +94 -57
- data/lib/rails/generators/base.rb +40 -1
- data/lib/rails/generators/css/assets/assets_generator.rb +3 -1
- data/lib/rails/generators/css/scaffold/scaffold_generator.rb +5 -3
- data/lib/rails/generators/erb.rb +2 -0
- data/lib/rails/generators/erb/controller/controller_generator.rb +2 -0
- data/lib/rails/generators/erb/controller/templates/{view.html.erb → view.html.erb.tt} +0 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +2 -0
- data/lib/rails/generators/erb/mailer/templates/{view.html.erb → view.html.erb.tt} +0 -0
- data/lib/rails/generators/erb/mailer/templates/{view.text.erb → view.text.erb.tt} +0 -0
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
- data/lib/rails/generators/erb/scaffold/templates/{_form.html.erb → _form.html.erb.tt} +4 -4
- data/lib/rails/generators/erb/scaffold/templates/{edit.html.erb → edit.html.erb.tt} +0 -0
- data/lib/rails/generators/erb/scaffold/templates/{index.html.erb → index.html.erb.tt} +4 -4
- data/lib/rails/generators/erb/scaffold/templates/{new.html.erb → new.html.erb.tt} +0 -0
- data/lib/rails/generators/erb/scaffold/templates/{show.html.erb → show.html.erb.tt} +0 -0
- data/lib/rails/generators/generated_attribute.rb +3 -1
- data/lib/rails/generators/js/assets/assets_generator.rb +3 -1
- data/lib/rails/generators/migration.rb +2 -0
- data/lib/rails/generators/model_helpers.rb +2 -0
- data/lib/rails/generators/named_base.rb +35 -45
- data/lib/rails/generators/rails/app/app_generator.rb +64 -23
- data/lib/rails/generators/rails/app/templates/{Gemfile → Gemfile.tt} +17 -6
- data/lib/rails/generators/rails/app/templates/{README.md → README.md.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/{Rakefile → Rakefile.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +3 -0
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/{cable.js → cable.js.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/{application.css → application.css.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/{channel.rb → channel.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/{connection.rb → connection.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +1 -4
- data/lib/rails/generators/rails/app/templates/app/helpers/{application_helper.rb → application_helper.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/jobs/{application_job.rb → application_job.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/mailers/{application_mailer.rb → application_mailer.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/app/models/{application_record.rb → application_record.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/bin/bundle.tt +2 -0
- data/lib/rails/generators/rails/app/templates/bin/{rails → rails.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/bin/{rake → rake.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +5 -5
- data/lib/rails/generators/rails/app/templates/bin/update.tt +7 -3
- data/lib/rails/generators/rails/app/templates/bin/{yarn → yarn.tt} +3 -3
- data/lib/rails/generators/rails/app/templates/{config.ru → config.ru.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/{application.rb → application.rb.tt} +2 -1
- data/lib/rails/generators/rails/app/templates/config/{boot.rb → boot.rb.tt} +1 -0
- data/lib/rails/generators/rails/app/templates/config/{cable.yml → cable.yml.tt} +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/{frontbase.yml → frontbase.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{ibm_db.yml → ibm_db.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{jdbc.yml → jdbc.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{jdbcmysql.yml → jdbcmysql.yml.tt} +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/{jdbcpostgresql.yml → jdbcpostgresql.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{jdbcsqlite3.yml → jdbcsqlite3.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{mysql.yml → mysql.yml.tt} +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/{oracle.yml → oracle.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{postgresql.yml → postgresql.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{sqlite3.yml → sqlite3.yml.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/databases/{sqlserver.yml → sqlserver.yml.tt} +2 -2
- data/lib/rails/generators/rails/app/templates/config/{environment.rb → environment.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +7 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +12 -7
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +8 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/{application_controller_renderer.rb → application_controller_renderer.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{backtrace_silencers.rb → backtrace_silencers.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +20 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{cookies_serializer.rb → cookies_serializer.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{cors.rb → cors.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{filter_parameter_logging.rb → filter_parameter_logging.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{inflections.rb → inflections.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{mime_types.rb → mime_types.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +27 -0
- data/lib/rails/generators/rails/app/templates/config/{puma.rb → puma.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/{routes.rb → routes.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/config/{spring.rb → spring.rb.tt} +2 -2
- data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +35 -0
- data/lib/rails/generators/rails/app/templates/{gitignore → gitignore.tt} +9 -1
- data/lib/rails/generators/rails/app/templates/{package.json → package.json.tt} +0 -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 → application_system_test_case.rb.tt} +0 -0
- data/lib/rails/generators/rails/app/templates/test/{test_helper.rb → test_helper.rb.tt} +1 -2
- data/lib/rails/generators/rails/application_record/application_record_generator.rb +9 -0
- data/lib/rails/generators/rails/assets/assets_generator.rb +2 -0
- data/lib/rails/generators/rails/assets/templates/stylesheet.css +1 -1
- data/lib/rails/generators/rails/controller/controller_generator.rb +11 -9
- data/lib/rails/generators/rails/controller/templates/{controller.rb → controller.rb.tt} +0 -0
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +48 -0
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +38 -0
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +57 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -0
- data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
- data/lib/rails/generators/rails/helper/helper_generator.rb +2 -0
- data/lib/rails/generators/rails/helper/templates/{helper.rb → helper.rb.tt} +0 -0
- data/lib/rails/generators/rails/integration_test/integration_test_generator.rb +2 -0
- data/lib/rails/generators/rails/master_key/master_key_generator.rb +51 -0
- data/lib/rails/generators/rails/migration/migration_generator.rb +2 -0
- data/lib/rails/generators/rails/model/model_generator.rb +2 -0
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +18 -9
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +24 -0
- data/lib/rails/generators/rails/plugin/templates/{Gemfile → Gemfile.tt} +1 -0
- data/lib/rails/generators/rails/plugin/templates/{MIT-LICENSE → MIT-LICENSE.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/{README.md → README.md.tt} +1 -1
- data/lib/rails/generators/rails/plugin/templates/{Rakefile → Rakefile.tt} +6 -7
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +21 -4
- data/lib/rails/generators/rails/plugin/templates/bin/test.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/config/{routes.rb → routes.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +18 -0
- data/lib/rails/generators/rails/plugin/templates/lib/{%namespaced_name%.rb → %namespaced_name%.rb.tt} +3 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/{engine.rb → engine.rb.tt} +0 -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 → version.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/lib/tasks/{%namespaced_name%_tasks.rake → %namespaced_name%_tasks.rake.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/rails/{application.rb → application.rb.tt} +6 -3
- data/lib/rails/generators/rails/plugin/templates/rails/{boot.rb → boot.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/rails/{dummy_manifest.js → dummy_manifest.js.tt} +0 -1
- data/lib/rails/generators/rails/plugin/templates/rails/{engine_manifest.js → engine_manifest.js.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/rails/{javascripts.js → javascripts.js.tt} +3 -0
- data/lib/rails/generators/rails/plugin/templates/rails/{routes.rb → routes.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/test/{%namespaced_name%_test.rb → %namespaced_name%_test.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/test/{application_system_test_case.rb → application_system_test_case.rb.tt} +0 -0
- data/lib/rails/generators/rails/plugin/templates/test/integration/{navigation_test.rb → navigation_test.rb.tt} +0 -1
- data/lib/rails/generators/rails/plugin/templates/test/{test_helper.rb → test_helper.rb.tt} +7 -6
- data/lib/rails/generators/rails/resource/USAGE +1 -1
- data/lib/rails/generators/rails/resource/resource_generator.rb +2 -0
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +21 -24
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -3
- data/lib/rails/generators/rails/scaffold_controller/USAGE +1 -1
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/{api_controller.rb → api_controller.rb.tt} +0 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/{controller.rb → controller.rb.tt} +2 -2
- data/lib/rails/generators/rails/system_test/system_test_generator.rb +2 -0
- data/lib/rails/generators/rails/task/task_generator.rb +2 -0
- data/lib/rails/generators/rails/task/templates/{task.rb → task.rb.tt} +0 -0
- data/lib/rails/generators/resource_helpers.rb +2 -0
- data/lib/rails/generators/test_case.rb +4 -2
- data/lib/rails/generators/test_unit.rb +2 -0
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
- data/lib/rails/generators/test_unit/controller/templates/{functional_test.rb → functional_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +2 -0
- data/lib/rails/generators/test_unit/generator/templates/{generator_test.rb → generator_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/helper/helper_generator.rb +2 -0
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -0
- data/lib/rails/generators/test_unit/integration/templates/{integration_test.rb → integration_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/job/job_generator.rb +3 -1
- data/lib/rails/generators/test_unit/job/templates/{unit_test.rb.erb → unit_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +2 -0
- data/lib/rails/generators/test_unit/mailer/templates/{functional_test.rb → functional_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/mailer/templates/{preview.rb → preview.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/model/model_generator.rb +2 -0
- data/lib/rails/generators/test_unit/model/templates/{fixtures.yml → fixtures.yml.tt} +0 -0
- data/lib/rails/generators/test_unit/model/templates/{unit_test.rb → unit_test.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -0
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +17 -4
- data/lib/rails/generators/test_unit/scaffold/templates/{api_functional_test.rb → api_functional_test.rb.tt} +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/{functional_test.rb → functional_test.rb.tt} +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +49 -0
- data/lib/rails/generators/test_unit/system/system_generator.rb +3 -1
- data/lib/rails/generators/test_unit/system/templates/{application_system_test_case.rb → application_system_test_case.rb.tt} +0 -0
- data/lib/rails/generators/test_unit/system/templates/{system_test.rb → system_test.rb.tt} +0 -0
- data/lib/rails/generators/testing/assertions.rb +7 -1
- data/lib/rails/generators/testing/behaviour.rb +8 -6
- data/lib/rails/generators/testing/setup_and_teardown.rb +2 -0
- data/lib/rails/info.rb +6 -3
- data/lib/rails/info_controller.rb +2 -0
- data/lib/rails/initializable.rb +2 -0
- data/lib/rails/mailers_controller.rb +9 -1
- data/lib/rails/paths.rb +2 -0
- data/lib/rails/plugin/test.rb +4 -2
- data/lib/rails/rack.rb +2 -0
- data/lib/rails/rack/logger.rb +5 -3
- data/lib/rails/railtie.rb +9 -4
- data/lib/rails/railtie/configurable.rb +2 -0
- data/lib/rails/railtie/configuration.rb +2 -0
- data/lib/rails/ruby_version_check.rb +3 -1
- data/lib/rails/secrets.rb +2 -17
- data/lib/rails/source_annotation_extractor.rb +4 -2
- data/lib/rails/tasks.rb +2 -0
- data/lib/rails/tasks/annotations.rake +2 -0
- data/lib/rails/tasks/dev.rake +2 -0
- data/lib/rails/tasks/engine.rake +7 -2
- data/lib/rails/tasks/framework.rake +9 -24
- data/lib/rails/tasks/initializers.rake +2 -0
- data/lib/rails/tasks/log.rake +2 -0
- data/lib/rails/tasks/middleware.rake +2 -0
- data/lib/rails/tasks/misc.rake +2 -0
- data/lib/rails/tasks/restart.rake +2 -1
- data/lib/rails/tasks/routes.rake +2 -0
- data/lib/rails/tasks/statistics.rake +2 -0
- data/lib/rails/tasks/tmp.rake +11 -2
- data/lib/rails/tasks/yarn.rake +3 -1
- data/lib/rails/templates/rails/mailers/email.html.erb +3 -3
- data/lib/rails/templates/rails/welcome/index.html.erb +14 -4
- data/lib/rails/test_help.rb +2 -0
- data/lib/rails/test_unit/line_filtering.rb +2 -1
- data/lib/rails/test_unit/railtie.rb +2 -0
- data/lib/rails/test_unit/reporter.rb +5 -10
- data/lib/rails/test_unit/runner.rb +3 -3
- data/lib/rails/test_unit/testing.rake +3 -1
- data/lib/rails/version.rb +2 -0
- data/lib/rails/welcome_controller.rb +2 -0
- metadata +121 -107
- data/lib/rails/generators/rails/app/templates/bin/bundle +0 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt +0 -16
- data/lib/rails/generators/rails/app/templates/config/secrets.yml +0 -32
- data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +0 -70
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +0 -33
- data/lib/rails/generators/rails/plugin/templates/gitignore +0 -9
data/lib/rails/generators.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
activesupport_path = File.expand_path("../../../activesupport/lib", __dir__)
|
2
4
|
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
|
3
5
|
|
4
6
|
require "thor/group"
|
@@ -10,6 +12,7 @@ require "active_support/core_ext/kernel/singleton_class"
|
|
10
12
|
require "active_support/core_ext/array/extract_options"
|
11
13
|
require "active_support/core_ext/hash/deep_merge"
|
12
14
|
require "active_support/core_ext/module/attribute_accessors"
|
15
|
+
require "active_support/core_ext/string/indent"
|
13
16
|
require "active_support/core_ext/string/inflections"
|
14
17
|
|
15
18
|
module Rails
|
@@ -215,6 +218,7 @@ module Rails
|
|
215
218
|
rails.delete("app")
|
216
219
|
rails.delete("plugin")
|
217
220
|
rails.delete("encrypted_secrets")
|
221
|
+
rails.delete("credentials")
|
218
222
|
|
219
223
|
hidden_namespaces.each { |n| groups.delete(n.to_s) }
|
220
224
|
|
@@ -270,8 +274,9 @@ module Rails
|
|
270
274
|
else
|
271
275
|
options = sorted_groups.flat_map(&:last)
|
272
276
|
suggestions = options.sort_by { |suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3)
|
273
|
-
|
274
|
-
msg
|
277
|
+
suggestions.map! { |s| "'#{s}'" }
|
278
|
+
msg = "Could not find generator '#{namespace}'. ".dup
|
279
|
+
msg << "Maybe you meant #{ suggestions[0...-1].join(', ')} or #{suggestions[-1]}\n"
|
275
280
|
msg << "Run `rails generate --help` for more options."
|
276
281
|
puts msg
|
277
282
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rails
|
2
4
|
module Generators
|
3
5
|
module Actions
|
@@ -11,17 +13,22 @@ module Rails
|
|
11
13
|
#
|
12
14
|
# gem "rspec", group: :test
|
13
15
|
# gem "technoweenie-restful-authentication", lib: "restful-authentication", source: "http://gems.github.com/"
|
14
|
-
# gem "rails", "3.0", git: "
|
16
|
+
# gem "rails", "3.0", git: "https://github.com/rails/rails"
|
17
|
+
# gem "RedCloth", ">= 4.1.0", "< 4.2.0"
|
15
18
|
def gem(*args)
|
16
19
|
options = args.extract_options!
|
17
|
-
name,
|
20
|
+
name, *versions = args
|
18
21
|
|
19
22
|
# Set the message to be shown in logs. Uses the git repo if one is given,
|
20
23
|
# otherwise use name (version).
|
21
24
|
parts, message = [ quote(name) ], name.dup
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
|
26
|
+
if versions = versions.any? ? versions : options.delete(:version)
|
27
|
+
_versions = Array(versions)
|
28
|
+
_versions.each do |version|
|
29
|
+
parts << quote(version)
|
30
|
+
end
|
31
|
+
message << " (#{_versions.join(", ")})"
|
25
32
|
end
|
26
33
|
message = options[:git] if options[:git]
|
27
34
|
|
@@ -97,16 +104,16 @@ module Rails
|
|
97
104
|
# "config.action_controller.asset_host = 'localhost:3000'"
|
98
105
|
# end
|
99
106
|
def environment(data = nil, options = {})
|
100
|
-
sentinel =
|
101
|
-
env_file_sentinel =
|
102
|
-
data
|
107
|
+
sentinel = "class Application < Rails::Application\n"
|
108
|
+
env_file_sentinel = "Rails.application.configure do\n"
|
109
|
+
data ||= yield if block_given?
|
103
110
|
|
104
111
|
in_root do
|
105
112
|
if options[:env].nil?
|
106
|
-
inject_into_file "config/application.rb",
|
113
|
+
inject_into_file "config/application.rb", optimize_indentation(data, 4), after: sentinel, verbose: false
|
107
114
|
else
|
108
115
|
Array(options[:env]).each do |env|
|
109
|
-
inject_into_file "config/environments/#{env}.rb",
|
116
|
+
inject_into_file "config/environments/#{env}.rb", optimize_indentation(data, 2), after: env_file_sentinel, verbose: false
|
110
117
|
end
|
111
118
|
end
|
112
119
|
end
|
@@ -137,12 +144,13 @@ module Rails
|
|
137
144
|
# end
|
138
145
|
#
|
139
146
|
# vendor("foreign.rb", "# Foreign code is fun")
|
140
|
-
def vendor(filename, data = nil
|
147
|
+
def vendor(filename, data = nil)
|
141
148
|
log :vendor, filename
|
142
|
-
|
149
|
+
data ||= yield if block_given?
|
150
|
+
create_file("vendor/#{filename}", optimize_indentation(data), verbose: false)
|
143
151
|
end
|
144
152
|
|
145
|
-
# Create a new file in the lib
|
153
|
+
# Create a new file in the <tt>lib/</tt> directory. Code can be specified
|
146
154
|
# in a block or a data string can be given.
|
147
155
|
#
|
148
156
|
# lib("crypto.rb") do
|
@@ -150,9 +158,10 @@ module Rails
|
|
150
158
|
# end
|
151
159
|
#
|
152
160
|
# lib("foreign.rb", "# Foreign code is fun")
|
153
|
-
def lib(filename, data = nil
|
161
|
+
def lib(filename, data = nil)
|
154
162
|
log :lib, filename
|
155
|
-
|
163
|
+
data ||= yield if block_given?
|
164
|
+
create_file("lib/#{filename}", optimize_indentation(data), verbose: false)
|
156
165
|
end
|
157
166
|
|
158
167
|
# Create a new +Rakefile+ with the provided code (either in a block or a string).
|
@@ -170,9 +179,10 @@ module Rails
|
|
170
179
|
# end
|
171
180
|
#
|
172
181
|
# rakefile('seed.rake', 'puts "Planting seeds"')
|
173
|
-
def rakefile(filename, data = nil
|
182
|
+
def rakefile(filename, data = nil)
|
174
183
|
log :rakefile, filename
|
175
|
-
|
184
|
+
data ||= yield if block_given?
|
185
|
+
create_file("lib/tasks/#{filename}", optimize_indentation(data), verbose: false)
|
176
186
|
end
|
177
187
|
|
178
188
|
# Create a new initializer with the provided code (either in a block or a string).
|
@@ -188,9 +198,10 @@ module Rails
|
|
188
198
|
# end
|
189
199
|
#
|
190
200
|
# initializer("api.rb", "API_KEY = '123456'")
|
191
|
-
def initializer(filename, data = nil
|
201
|
+
def initializer(filename, data = nil)
|
192
202
|
log :initializer, filename
|
193
|
-
|
203
|
+
data ||= yield if block_given?
|
204
|
+
create_file("config/initializers/#{filename}", optimize_indentation(data), verbose: false)
|
194
205
|
end
|
195
206
|
|
196
207
|
# Generate something using a generator from Rails or a plugin.
|
@@ -210,15 +221,17 @@ module Rails
|
|
210
221
|
# rake("db:migrate")
|
211
222
|
# rake("db:migrate", env: "production")
|
212
223
|
# rake("gems:install", sudo: true)
|
224
|
+
# rake("gems:install", capture: true)
|
213
225
|
def rake(command, options = {})
|
214
226
|
execute_command :rake, command, options
|
215
227
|
end
|
216
228
|
|
217
229
|
# Runs the supplied rake task (invoked with 'rails ...')
|
218
230
|
#
|
219
|
-
#
|
220
|
-
#
|
221
|
-
#
|
231
|
+
# rails_command("db:migrate")
|
232
|
+
# rails_command("db:migrate", env: "production")
|
233
|
+
# rails_command("gems:install", sudo: true)
|
234
|
+
# rails_command("gems:install", capture: true)
|
222
235
|
def rails_command(command, options = {})
|
223
236
|
execute_command :rails, command, options
|
224
237
|
end
|
@@ -227,6 +240,7 @@ module Rails
|
|
227
240
|
#
|
228
241
|
# capify!
|
229
242
|
def capify!
|
243
|
+
ActiveSupport::Deprecation.warn("`capify!` is deprecated and will be removed in the next version of Rails.")
|
230
244
|
log :capify, ""
|
231
245
|
in_root { run("#{extify(:capify)} .", verbose: false) }
|
232
246
|
end
|
@@ -239,7 +253,7 @@ module Rails
|
|
239
253
|
sentinel = /\.routes\.draw do\s*\n/m
|
240
254
|
|
241
255
|
in_root do
|
242
|
-
inject_into_file "config/routes.rb",
|
256
|
+
inject_into_file "config/routes.rb", optimize_indentation(routing_code, 2), after: sentinel, verbose: false, force: false
|
243
257
|
end
|
244
258
|
end
|
245
259
|
|
@@ -280,7 +294,11 @@ module Rails
|
|
280
294
|
log executor, command
|
281
295
|
env = options[:env] || ENV["RAILS_ENV"] || "development"
|
282
296
|
sudo = options[:sudo] && !Gem.win_platform? ? "sudo " : ""
|
283
|
-
|
297
|
+
config = { verbose: false }
|
298
|
+
|
299
|
+
config.merge!(capture: options[:capture]) if options[:capture]
|
300
|
+
|
301
|
+
in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", config) }
|
284
302
|
end
|
285
303
|
|
286
304
|
# Add an extension to the given name based on the platform.
|
@@ -303,6 +321,17 @@ module Rails
|
|
303
321
|
"'#{value}'"
|
304
322
|
end
|
305
323
|
end
|
324
|
+
|
325
|
+
# Returns optimized string with indentation
|
326
|
+
def optimize_indentation(value, amount = 0) # :doc:
|
327
|
+
return "#{value}\n" unless value.is_a?(String)
|
328
|
+
|
329
|
+
if value.lines.size > 1
|
330
|
+
value.strip_heredoc.indent(amount)
|
331
|
+
else
|
332
|
+
"#{value.strip.indent(amount)}\n"
|
333
|
+
end
|
334
|
+
end
|
306
335
|
end
|
307
336
|
end
|
308
337
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "fileutils"
|
2
4
|
require "digest/md5"
|
3
5
|
require "active_support/core_ext/string/strip"
|
@@ -24,75 +26,78 @@ module Rails
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def self.add_shared_options_for(name)
|
27
|
-
class_option :template,
|
28
|
-
|
29
|
+
class_option :template, type: :string, aliases: "-m",
|
30
|
+
desc: "Path to some #{name} template (can be a filesystem path or URL)"
|
31
|
+
|
32
|
+
class_option :database, type: :string, aliases: "-d", default: "sqlite3",
|
33
|
+
desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
|
29
34
|
|
30
|
-
class_option :
|
31
|
-
|
35
|
+
class_option :skip_yarn, type: :boolean, default: false,
|
36
|
+
desc: "Don't use Yarn for managing JavaScript dependencies"
|
32
37
|
|
33
|
-
class_option :
|
34
|
-
|
38
|
+
class_option :skip_gemfile, type: :boolean, default: false,
|
39
|
+
desc: "Don't create a Gemfile"
|
35
40
|
|
36
|
-
class_option :
|
37
|
-
|
41
|
+
class_option :skip_git, type: :boolean, aliases: "-G", default: false,
|
42
|
+
desc: "Skip .gitignore file"
|
38
43
|
|
39
|
-
class_option :
|
40
|
-
|
44
|
+
class_option :skip_keeps, type: :boolean, default: false,
|
45
|
+
desc: "Skip source control .keep files"
|
41
46
|
|
42
|
-
class_option :
|
43
|
-
|
47
|
+
class_option :skip_action_mailer, type: :boolean, aliases: "-M",
|
48
|
+
default: false,
|
49
|
+
desc: "Skip Action Mailer files"
|
44
50
|
|
45
|
-
class_option :
|
46
|
-
|
47
|
-
desc: "Skip Action Mailer files"
|
51
|
+
class_option :skip_active_record, type: :boolean, aliases: "-O", default: false,
|
52
|
+
desc: "Skip Active Record files"
|
48
53
|
|
49
|
-
class_option :
|
50
|
-
|
54
|
+
class_option :skip_active_storage, type: :boolean, default: false,
|
55
|
+
desc: "Skip Active Storage files"
|
51
56
|
|
52
|
-
class_option :skip_puma,
|
53
|
-
|
57
|
+
class_option :skip_puma, type: :boolean, aliases: "-P", default: false,
|
58
|
+
desc: "Skip Puma related files"
|
54
59
|
|
55
|
-
class_option :skip_action_cable,
|
56
|
-
|
60
|
+
class_option :skip_action_cable, type: :boolean, aliases: "-C", default: false,
|
61
|
+
desc: "Skip Action Cable files"
|
57
62
|
|
58
|
-
class_option :skip_sprockets,
|
59
|
-
|
63
|
+
class_option :skip_sprockets, type: :boolean, aliases: "-S", default: false,
|
64
|
+
desc: "Skip Sprockets files"
|
60
65
|
|
61
|
-
class_option :skip_spring,
|
62
|
-
|
66
|
+
class_option :skip_spring, type: :boolean, default: false,
|
67
|
+
desc: "Don't install Spring application preloader"
|
63
68
|
|
64
|
-
class_option :skip_listen,
|
65
|
-
|
69
|
+
class_option :skip_listen, type: :boolean, default: false,
|
70
|
+
desc: "Don't generate configuration that depends on the listen gem"
|
66
71
|
|
67
|
-
class_option :skip_coffee,
|
68
|
-
|
72
|
+
class_option :skip_coffee, type: :boolean, default: false,
|
73
|
+
desc: "Don't use CoffeeScript"
|
69
74
|
|
70
|
-
class_option :skip_javascript,
|
71
|
-
|
75
|
+
class_option :skip_javascript, type: :boolean, aliases: "-J", default: false,
|
76
|
+
desc: "Skip JavaScript files"
|
72
77
|
|
73
|
-
class_option :skip_turbolinks,
|
74
|
-
|
78
|
+
class_option :skip_turbolinks, type: :boolean, default: false,
|
79
|
+
desc: "Skip turbolinks gem"
|
75
80
|
|
76
|
-
class_option :skip_test,
|
77
|
-
|
81
|
+
class_option :skip_test, type: :boolean, aliases: "-T", default: false,
|
82
|
+
desc: "Skip test files"
|
78
83
|
|
79
|
-
class_option :skip_system_test,
|
80
|
-
|
84
|
+
class_option :skip_system_test, type: :boolean, default: false,
|
85
|
+
desc: "Skip system test files"
|
81
86
|
|
82
|
-
class_option :dev,
|
83
|
-
|
87
|
+
class_option :dev, type: :boolean, default: false,
|
88
|
+
desc: "Setup the #{name} with Gemfile pointing to your Rails checkout"
|
84
89
|
|
85
|
-
class_option :edge,
|
86
|
-
|
90
|
+
class_option :edge, type: :boolean, default: false,
|
91
|
+
desc: "Setup the #{name} with Gemfile pointing to Rails repository"
|
87
92
|
|
88
|
-
class_option :rc,
|
89
|
-
|
93
|
+
class_option :rc, type: :string, default: nil,
|
94
|
+
desc: "Path to file containing extra configuration options for rails command"
|
90
95
|
|
91
|
-
class_option :no_rc,
|
92
|
-
|
96
|
+
class_option :no_rc, type: :boolean, default: false,
|
97
|
+
desc: "Skip loading of extra configuration options from .railsrc file"
|
93
98
|
|
94
|
-
class_option :help,
|
95
|
-
|
99
|
+
class_option :help, type: :boolean, aliases: "-h", group: :rails,
|
100
|
+
desc: "Show this help message and quit"
|
96
101
|
end
|
97
102
|
|
98
103
|
def initialize(*args)
|
@@ -187,15 +192,33 @@ module Rails
|
|
187
192
|
def webserver_gemfile_entry # :doc:
|
188
193
|
return [] if options[:skip_puma]
|
189
194
|
comment = "Use Puma as the app server"
|
190
|
-
GemfileEntry.new("puma", "~> 3.
|
195
|
+
GemfileEntry.new("puma", "~> 3.11", comment)
|
191
196
|
end
|
192
197
|
|
193
198
|
def include_all_railties? # :doc:
|
194
|
-
|
199
|
+
[
|
200
|
+
options.values_at(
|
201
|
+
:skip_active_record,
|
202
|
+
:skip_action_mailer,
|
203
|
+
:skip_test,
|
204
|
+
:skip_sprockets,
|
205
|
+
:skip_action_cable
|
206
|
+
),
|
207
|
+
skip_active_storage?
|
208
|
+
].flatten.none?
|
195
209
|
end
|
196
210
|
|
197
211
|
def comment_if(value) # :doc:
|
198
|
-
|
212
|
+
question = "#{value}?"
|
213
|
+
|
214
|
+
comment =
|
215
|
+
if respond_to?(question, true)
|
216
|
+
send(question)
|
217
|
+
else
|
218
|
+
options[value]
|
219
|
+
end
|
220
|
+
|
221
|
+
comment ? "# " : ""
|
199
222
|
end
|
200
223
|
|
201
224
|
def keeps? # :doc:
|
@@ -206,6 +229,10 @@ module Rails
|
|
206
229
|
!options[:skip_active_record] && options[:database] == "sqlite3"
|
207
230
|
end
|
208
231
|
|
232
|
+
def skip_active_storage? # :doc:
|
233
|
+
options[:skip_active_storage] || options[:skip_active_record]
|
234
|
+
end
|
235
|
+
|
209
236
|
class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out)
|
210
237
|
def initialize(name, version, comment, options = {}, commented_out = false)
|
211
238
|
super
|
@@ -239,16 +266,14 @@ module Rails
|
|
239
266
|
end
|
240
267
|
|
241
268
|
def rails_gemfile_entry
|
242
|
-
dev_edge_common = [
|
243
|
-
]
|
244
269
|
if options.dev?
|
245
270
|
[
|
246
271
|
GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH)
|
247
|
-
]
|
272
|
+
]
|
248
273
|
elsif options.edge?
|
249
274
|
[
|
250
275
|
GemfileEntry.github("rails", "rails/rails")
|
251
|
-
]
|
276
|
+
]
|
252
277
|
else
|
253
278
|
[GemfileEntry.version("rails",
|
254
279
|
rails_version_specifier,
|
@@ -272,8 +297,8 @@ module Rails
|
|
272
297
|
def gem_for_database
|
273
298
|
# %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql )
|
274
299
|
case options[:database]
|
275
|
-
when "mysql" then ["mysql2", [">= 0.3.18", "< 0.
|
276
|
-
when "postgresql" then ["pg", ["
|
300
|
+
when "mysql" then ["mysql2", [">= 0.3.18", "< 0.5"]]
|
301
|
+
when "postgresql" then ["pg", ["~> 0.18"]]
|
277
302
|
when "oracle" then ["activerecord-oracle_enhanced-adapter", nil]
|
278
303
|
when "frontbase" then ["ruby-frontbase", nil]
|
279
304
|
when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
|
@@ -347,8 +372,10 @@ module Rails
|
|
347
372
|
comment = "See https://github.com/rails/execjs#readme for more supported runtimes"
|
348
373
|
if defined?(JRUBY_VERSION)
|
349
374
|
GemfileEntry.version "therubyrhino", nil, comment
|
375
|
+
elsif RUBY_PLATFORM =~ /mingw|mswin/
|
376
|
+
GemfileEntry.version "duktape", nil, comment
|
350
377
|
else
|
351
|
-
GemfileEntry.new "
|
378
|
+
GemfileEntry.new "mini_racer", nil, comment, { platforms: :ruby }, true
|
352
379
|
end
|
353
380
|
end
|
354
381
|
|
@@ -429,6 +456,16 @@ module Rails
|
|
429
456
|
end
|
430
457
|
end
|
431
458
|
|
459
|
+
def run_active_storage
|
460
|
+
unless skip_active_storage?
|
461
|
+
if bundle_install?
|
462
|
+
rails_command "active_storage:install", capture: options[:quiet]
|
463
|
+
else
|
464
|
+
log("Active Storage installation was skipped. Please run `bin/rails active_storage:install` to install Active Storage files.")
|
465
|
+
end
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
432
469
|
def empty_directory_with_keep_file(destination, config = {})
|
433
470
|
empty_directory(destination, config)
|
434
471
|
keep_file(destination)
|