railties 5.2.3 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +306 -126
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +38 -31
- data/README.rdoc +2 -2
- data/lib/minitest/rails_plugin.rb +7 -11
- data/lib/rails.rb +5 -0
- data/lib/rails/all.rb +4 -0
- data/lib/rails/api/generator.rb +2 -1
- data/lib/rails/api/task.rb +16 -0
- data/lib/rails/app_loader.rb +2 -2
- data/lib/rails/app_updater.rb +3 -1
- data/lib/rails/application.rb +71 -29
- data/lib/rails/application/bootstrap.rb +2 -10
- data/lib/rails/application/configuration.rb +113 -13
- data/lib/rails/application/default_middleware_stack.rb +3 -0
- data/lib/rails/application/dummy_erb_compiler.rb +18 -0
- data/lib/rails/application/finisher.rb +54 -0
- data/lib/rails/autoloaders.rb +48 -0
- data/lib/rails/backtrace_cleaner.rb +5 -17
- data/lib/rails/code_statistics.rb +3 -3
- data/lib/rails/command.rb +11 -10
- data/lib/rails/command/base.rb +12 -4
- data/lib/rails/command/behavior.rb +7 -48
- data/lib/rails/command/environment_argument.rb +8 -15
- data/lib/rails/command/spellchecker.rb +58 -0
- data/lib/rails/commands/console/console_command.rb +6 -0
- data/lib/rails/commands/credentials/USAGE +19 -1
- data/lib/rails/commands/credentials/credentials_command.rb +52 -19
- data/lib/rails/commands/db/system/change/change_command.rb +20 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +20 -8
- data/lib/rails/commands/dev/dev_command.rb +19 -0
- data/lib/rails/commands/encrypted/USAGE +1 -1
- data/lib/rails/commands/encrypted/encrypted_command.rb +2 -2
- data/lib/rails/commands/help/help_command.rb +1 -1
- data/lib/rails/commands/initializers/initializers_command.rb +23 -0
- data/lib/rails/commands/new/new_command.rb +2 -2
- data/lib/rails/commands/notes/notes_command.rb +39 -0
- data/lib/rails/commands/plugin/plugin_command.rb +1 -1
- data/lib/rails/commands/routes/routes_command.rb +37 -0
- data/lib/rails/commands/runner/runner_command.rb +13 -9
- data/lib/rails/commands/secrets/USAGE +3 -3
- data/lib/rails/commands/secrets/secrets_command.rb +3 -3
- data/lib/rails/commands/server/server_command.rb +113 -50
- data/lib/rails/configuration.rb +1 -7
- data/lib/rails/engine.rb +32 -18
- data/lib/rails/engine/configuration.rb +5 -2
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators.rb +11 -10
- data/lib/rails/generators/actions.rb +52 -39
- data/lib/rails/generators/app_base.rb +59 -97
- data/lib/rails/generators/app_name.rb +50 -0
- data/lib/rails/generators/database.rb +58 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -1
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +6 -3
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +9 -1
- data/lib/rails/generators/generated_attribute.rb +53 -27
- data/lib/rails/generators/migration.rb +1 -2
- data/lib/rails/generators/model_helpers.rb +8 -1
- data/lib/rails/generators/named_base.rb +1 -5
- data/lib/rails/generators/rails/app/app_generator.rb +37 -71
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +7 -10
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
- data/lib/rails/generators/rails/app/templates/app/{assets/javascripts/cable.js.tt → javascript/channels/consumer.js} +2 -9
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +23 -0
- data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +7 -7
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +2 -0
- data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +6 -6
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +5 -2
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +28 -12
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +13 -7
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +7 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +45 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +7 -3
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
- data/lib/rails/generators/rails/app/templates/gitignore.tt +2 -7
- data/lib/rails/generators/rails/app/templates/package.json.tt +7 -1
- data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -1
- data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +7 -0
- data/lib/rails/generators/rails/assets/USAGE +1 -4
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -1
- data/lib/rails/generators/rails/controller/controller_generator.rb +11 -1
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +7 -8
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +65 -0
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +4 -5
- data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +9 -33
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +1 -2
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +14 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
- data/lib/rails/generators/resource_helpers.rb +1 -6
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +6 -0
- data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +8 -3
- data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
- data/lib/rails/generators/testing/behaviour.rb +3 -0
- data/lib/rails/info.rb +2 -2
- data/lib/rails/info_controller.rb +1 -1
- data/lib/rails/mailers_controller.rb +7 -4
- data/lib/rails/paths.rb +19 -9
- data/lib/rails/railtie.rb +1 -1
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +0 -1
- data/lib/rails/source_annotation_extractor.rb +138 -117
- data/lib/rails/tasks.rb +1 -0
- data/lib/rails/tasks/annotations.rake +9 -9
- data/lib/rails/tasks/dev.rake +5 -4
- data/lib/rails/tasks/framework.rake +5 -1
- data/lib/rails/tasks/initializers.rake +5 -4
- data/lib/rails/tasks/log.rake +0 -1
- data/lib/rails/tasks/routes.rake +4 -26
- data/lib/rails/tasks/statistics.rake +4 -0
- data/lib/rails/tasks/yarn.rake +1 -1
- data/lib/rails/tasks/zeitwerk.rake +66 -0
- data/lib/rails/templates/rails/welcome/index.html.erb +2 -2
- data/lib/rails/test_help.rb +11 -9
- data/lib/rails/test_unit/reporter.rb +1 -1
- data/lib/rails/test_unit/runner.rb +5 -5
- data/lib/rails/test_unit/testing.rake +1 -1
- metadata +31 -22
- data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
- data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
- data/lib/rails/generators/rails/app/templates/bin/update.tt +0 -34
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -38
- data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
@@ -1,11 +1,16 @@
|
|
1
|
+
# The test environment is used exclusively to run your application's
|
2
|
+
# test suite. You never need to work with it otherwise. Remember that
|
3
|
+
# your test database is "scratch space" for the test suite and is wiped
|
4
|
+
# and recreated between test runs. Don't rely on the data there!
|
5
|
+
|
1
6
|
Rails.application.configure do
|
2
7
|
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
<%# Spring executes the reloaders when files change. %>
|
9
|
+
<%- if spring_install? -%>
|
10
|
+
config.cache_classes = false
|
11
|
+
<%- else -%>
|
8
12
|
config.cache_classes = true
|
13
|
+
<%- end -%>
|
9
14
|
|
10
15
|
# Do not eager load code on boot. This avoids loading your whole application
|
11
16
|
# just for the purpose of running a single test. If you are using a tool that
|
@@ -21,6 +26,7 @@ Rails.application.configure do
|
|
21
26
|
# Show full error reports and disable caching.
|
22
27
|
config.consider_all_requests_local = true
|
23
28
|
config.action_controller.perform_caching = false
|
29
|
+
config.cache_store = :null_store
|
24
30
|
|
25
31
|
# Raise exceptions instead of rendering exception templates.
|
26
32
|
config.action_dispatch.show_exceptions = false
|
@@ -29,7 +35,7 @@ Rails.application.configure do
|
|
29
35
|
config.action_controller.allow_forgery_protection = false
|
30
36
|
|
31
37
|
<%- unless skip_active_storage? -%>
|
32
|
-
# Store uploaded files on the local file system in a temporary directory
|
38
|
+
# Store uploaded files on the local file system in a temporary directory.
|
33
39
|
config.active_storage.service = :test
|
34
40
|
|
35
41
|
<%- end -%>
|
@@ -45,6 +51,6 @@ Rails.application.configure do
|
|
45
51
|
# Print deprecation notices to the stderr.
|
46
52
|
config.active_support.deprecation = :stderr
|
47
53
|
|
48
|
-
# Raises error for missing translations
|
54
|
+
# Raises error for missing translations.
|
49
55
|
# config.action_view.raise_on_missing_translations = true
|
50
56
|
end
|
@@ -5,7 +5,7 @@ Rails.application.config.assets.version = '1.0'
|
|
5
5
|
|
6
6
|
# Add additional assets to the asset load path.
|
7
7
|
# Rails.application.config.assets.paths << Emoji.images_path
|
8
|
-
<%- unless options[:
|
8
|
+
<%- unless options[:skip_javascript] -%>
|
9
9
|
# Add Yarn node_modules folder to the asset load path.
|
10
10
|
Rails.application.config.assets.paths << Rails.root.join('node_modules')
|
11
11
|
<%- end -%>
|
data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt
CHANGED
@@ -11,6 +11,10 @@
|
|
11
11
|
# policy.object_src :none
|
12
12
|
# policy.script_src :self, :https
|
13
13
|
# policy.style_src :self, :https
|
14
|
+
<%- unless options[:skip_javascript] -%>
|
15
|
+
# # If you are using webpack-dev-server then specify webpack-dev-server host
|
16
|
+
# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
|
17
|
+
<%- end -%>
|
14
18
|
|
15
19
|
# # Specify URI for violation reports
|
16
20
|
# # policy.report_uri "/csp-violation-report-endpoint"
|
@@ -19,6 +23,9 @@
|
|
19
23
|
# If you are using UJS then enable automatic nonce generation
|
20
24
|
# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
|
21
25
|
|
26
|
+
# Set the nonce only to specific directives
|
27
|
+
# Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
|
28
|
+
|
22
29
|
# Report CSP violations to a specified URI
|
23
30
|
# For further information see the following documentation:
|
24
31
|
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
|
data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains migration options to ease your Rails 6.0 upgrade.
|
4
|
+
#
|
5
|
+
# Once upgraded flip defaults one by one to migrate to the new default.
|
6
|
+
#
|
7
|
+
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
|
8
|
+
|
9
|
+
# Don't force requests from old versions of IE to be UTF-8 encoded.
|
10
|
+
# Rails.application.config.action_view.default_enforce_utf8 = false
|
11
|
+
|
12
|
+
# Embed purpose and expiry metadata inside signed and encrypted
|
13
|
+
# cookies for increased security.
|
14
|
+
#
|
15
|
+
# This option is not backwards compatible with earlier Rails versions.
|
16
|
+
# It's best enabled when your entire app is migrated and stable on 6.0.
|
17
|
+
# Rails.application.config.action_dispatch.use_cookies_with_metadata = true
|
18
|
+
|
19
|
+
# Change the return value of `ActionDispatch::Response#content_type` to Content-Type header without modification.
|
20
|
+
# Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false
|
21
|
+
|
22
|
+
# Return false instead of self when enqueuing is aborted from a callback.
|
23
|
+
# Rails.application.config.active_job.return_false_on_aborted_enqueue = true
|
24
|
+
|
25
|
+
# Send Active Storage analysis and purge jobs to dedicated queues.
|
26
|
+
# Rails.application.config.active_storage.queues.analysis = :active_storage_analysis
|
27
|
+
# Rails.application.config.active_storage.queues.purge = :active_storage_purge
|
28
|
+
|
29
|
+
# When assigning to a collection of attachments declared via `has_many_attached`, replace existing
|
30
|
+
# attachments instead of appending. Use #attach to add new attachments without replacing existing ones.
|
31
|
+
# Rails.application.config.active_storage.replace_on_assign_to_many = true
|
32
|
+
|
33
|
+
# Use ActionMailer::MailDeliveryJob for sending parameterized and normal mail.
|
34
|
+
#
|
35
|
+
# The default delivery jobs (ActionMailer::Parameterized::DeliveryJob, ActionMailer::DeliveryJob),
|
36
|
+
# will be removed in Rails 6.1. This setting is not backwards compatible with earlier Rails versions.
|
37
|
+
# If you send mail in the background, job workers need to have a copy of
|
38
|
+
# MailDeliveryJob to ensure all delivery jobs are processed properly.
|
39
|
+
# Make sure your entire app is migrated and stable on 6.0 before using this setting.
|
40
|
+
# Rails.application.config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
|
41
|
+
|
42
|
+
# Enable the same cache key to be reused when the object being cached of type
|
43
|
+
# `ActiveRecord::Relation` changes by moving the volatile information (max updated at and count)
|
44
|
+
# of the relation's cache key into the cache version to support recycling cache key.
|
45
|
+
# Rails.application.config.active_record.collection_cache_versioning = true
|
@@ -4,8 +4,9 @@
|
|
4
4
|
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
5
5
|
# and maximum; this matches the default thread size of Active Record.
|
6
6
|
#
|
7
|
-
|
8
|
-
|
7
|
+
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
|
8
|
+
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
|
9
|
+
threads min_threads_count, max_threads_count
|
9
10
|
|
10
11
|
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
11
12
|
#
|
@@ -15,8 +16,11 @@ port ENV.fetch("PORT") { 3000 }
|
|
15
16
|
#
|
16
17
|
environment ENV.fetch("RAILS_ENV") { "development" }
|
17
18
|
|
19
|
+
# Specifies the `pidfile` that Puma will use.
|
20
|
+
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
|
21
|
+
|
18
22
|
# Specifies the number of `workers` to boot in clustered mode.
|
19
|
-
# Workers are forked
|
23
|
+
# Workers are forked web server processes. If using threads and workers together
|
20
24
|
# the concurrency of the application would be max `threads` * `workers`.
|
21
25
|
# Workers do not work on JRuby or Windows (both of which do not support
|
22
26
|
# processes).
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
.ruby-version
|
3
|
-
.rbenv-vars
|
4
|
-
tmp/restart.txt
|
5
|
-
tmp/caching-dev.txt
|
6
|
-
|
1
|
+
Spring.watch(
|
2
|
+
".ruby-version",
|
3
|
+
".rbenv-vars",
|
4
|
+
"tmp/restart.txt",
|
5
|
+
"tmp/caching-dev.txt"
|
6
|
+
)
|
@@ -22,19 +22,14 @@
|
|
22
22
|
<% end -%>
|
23
23
|
|
24
24
|
<% unless skip_active_storage? -%>
|
25
|
-
# Ignore uploaded files in development
|
25
|
+
# Ignore uploaded files in development.
|
26
26
|
/storage/*
|
27
27
|
<% if keeps? -%>
|
28
28
|
!/storage/.keep
|
29
29
|
<% end -%>
|
30
|
-
<% end -%>
|
31
|
-
|
32
|
-
<% unless options.skip_yarn? -%>
|
33
|
-
/node_modules
|
34
|
-
/yarn-error.log
|
35
|
-
|
36
30
|
<% end -%>
|
37
31
|
<% unless options.api? -%>
|
32
|
+
|
38
33
|
/public/assets
|
39
34
|
<% end -%>
|
40
35
|
.byebug_history
|
@@ -1,5 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "<%= app_name %>",
|
3
3
|
"private": true,
|
4
|
-
"dependencies": {
|
4
|
+
"dependencies": {
|
5
|
+
"@rails/ujs": "^6.0.0-alpha"<% unless options[:skip_turbolinks] %>,
|
6
|
+
"turbolinks": "^5.2.0"<% end -%><% unless skip_active_storage? %>,
|
7
|
+
"@rails/activestorage": "^6.0.0-alpha"<% end -%><% unless options[:skip_action_cable] %>,
|
8
|
+
"@rails/actioncable": "^6.0.0-alpha"<% end %>
|
9
|
+
},
|
10
|
+
"version": "0.1.0"
|
5
11
|
}
|
@@ -1 +1 @@
|
|
1
|
-
# See
|
1
|
+
# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
@@ -1 +1 @@
|
|
1
|
-
<%= ENV["RBENV_VERSION"] || ENV["rvm_ruby_string"] || "#{RUBY_ENGINE}-#{
|
1
|
+
<%= ENV["RBENV_VERSION"] || ENV["rvm_ruby_string"] || "#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}" %>
|
@@ -3,6 +3,13 @@ require_relative '../config/environment'
|
|
3
3
|
require 'rails/test_help'
|
4
4
|
|
5
5
|
class ActiveSupport::TestCase
|
6
|
+
# Run tests in parallel with specified workers
|
7
|
+
<% if defined?(JRUBY_VERSION) || Gem.win_platform? -%>
|
8
|
+
parallelize(workers: :number_of_processors, with: :threads)
|
9
|
+
<%- else -%>
|
10
|
+
parallelize(workers: :number_of_processors)
|
11
|
+
<% end -%>
|
12
|
+
|
6
13
|
<% unless options[:skip_active_record] -%>
|
7
14
|
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
8
15
|
fixtures :all
|
@@ -5,16 +5,13 @@ Description:
|
|
5
5
|
To create an asset within a folder, specify the asset's name as a
|
6
6
|
path like 'parent/name'.
|
7
7
|
|
8
|
-
This generates a
|
9
|
-
stub in app/assets/stylesheets.
|
8
|
+
This generates a stylesheet stub in app/assets/stylesheets.
|
10
9
|
|
11
|
-
If CoffeeScript is available, JavaScripts will be generated with the .coffee extension.
|
12
10
|
If Sass 3 is available, stylesheets will be generated with the .scss extension.
|
13
11
|
|
14
12
|
Example:
|
15
13
|
`rails generate assets posts`
|
16
14
|
|
17
15
|
Posts assets.
|
18
|
-
JavaScript: app/assets/javascripts/posts.js
|
19
16
|
Stylesheet: app/assets/stylesheets/posts.css
|
20
17
|
|
@@ -20,10 +20,20 @@ module Rails
|
|
20
20
|
route generate_routing_code
|
21
21
|
end
|
22
22
|
|
23
|
-
hook_for :template_engine, :test_framework, :helper, :assets
|
23
|
+
hook_for :template_engine, :test_framework, :helper, :assets do |generator|
|
24
|
+
invoke generator, [ remove_possible_suffix(name), actions ]
|
25
|
+
end
|
24
26
|
|
25
27
|
private
|
26
28
|
|
29
|
+
def file_name
|
30
|
+
@_file_name ||= remove_possible_suffix(super)
|
31
|
+
end
|
32
|
+
|
33
|
+
def remove_possible_suffix(name)
|
34
|
+
name.sub(/_?controller$/i, "")
|
35
|
+
end
|
36
|
+
|
27
37
|
# This method creates nested route entry for namespaced resources.
|
28
38
|
# For eg. rails g controller foo/bar/baz index show
|
29
39
|
# Will generate -
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require "rails/generators/base"
|
4
4
|
require "rails/generators/rails/master_key/master_key_generator"
|
5
|
-
require "active_support/core_ext/string/strip"
|
6
5
|
require "active_support/encrypted_configuration"
|
7
6
|
|
8
7
|
module Rails
|
@@ -21,7 +20,7 @@ module Rails
|
|
21
20
|
|
22
21
|
add_credentials_file_silently(template)
|
23
22
|
|
24
|
-
say "You can edit encrypted credentials with `
|
23
|
+
say "You can edit encrypted credentials with `rails credentials:edit`."
|
25
24
|
say ""
|
26
25
|
end
|
27
26
|
end
|
@@ -43,13 +42,13 @@ module Rails
|
|
43
42
|
end
|
44
43
|
|
45
44
|
def credentials_template
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
<<~YAML
|
46
|
+
# aws:
|
47
|
+
# access_key_id: 123
|
48
|
+
# secret_access_key: 345
|
50
49
|
|
51
|
-
|
52
|
-
|
50
|
+
# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
|
51
|
+
secret_key_base: #{SecureRandom.hex(64)}
|
53
52
|
YAML
|
54
53
|
end
|
55
54
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators/base"
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
module Generators
|
7
|
+
module Db
|
8
|
+
module System
|
9
|
+
class ChangeGenerator < Base # :nodoc:
|
10
|
+
include Database
|
11
|
+
include AppName
|
12
|
+
|
13
|
+
class_option :to, required: true,
|
14
|
+
desc: "The database system to switch to."
|
15
|
+
|
16
|
+
def self.default_generator_root
|
17
|
+
path = File.expand_path(File.join(base_name, "app"), base_root)
|
18
|
+
path if File.exist?(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(*)
|
22
|
+
super
|
23
|
+
|
24
|
+
unless DATABASES.include?(options[:to])
|
25
|
+
raise Error, "Invalid value for --to option. Supported preconfigurations are: #{DATABASES.join(", ")}."
|
26
|
+
end
|
27
|
+
|
28
|
+
opt = options.dup
|
29
|
+
opt[:database] ||= opt[:to]
|
30
|
+
self.options = opt.freeze
|
31
|
+
end
|
32
|
+
|
33
|
+
def edit_database_config
|
34
|
+
template("config/databases/#{options[:database]}.yml", "config/database.yml")
|
35
|
+
end
|
36
|
+
|
37
|
+
def edit_gemfile
|
38
|
+
name, version = gem_for_database
|
39
|
+
gsub_file("Gemfile", all_database_gems_regex, name)
|
40
|
+
gsub_file("Gemfile", gem_entry_regex_for(name), gem_entry_for(name, *version))
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def all_database_gems
|
45
|
+
DATABASES.map { |database| gem_for_database(database) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def all_database_gems_regex
|
49
|
+
all_database_gem_names = all_database_gems.map(&:first)
|
50
|
+
/(\b#{all_database_gem_names.join('\b|\b')}\b)/
|
51
|
+
end
|
52
|
+
|
53
|
+
def gem_entry_regex_for(gem_name)
|
54
|
+
/^gem.*\b#{gem_name}\b.*/
|
55
|
+
end
|
56
|
+
|
57
|
+
def gem_entry_for(*gem_name_and_version)
|
58
|
+
gem_name_and_version.map! { |segment| "'#{segment}'" }
|
59
|
+
"gem #{gem_name_and_version.join(", ")}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "rails/generators/base"
|
4
|
-
require "active_support/core_ext/string/strip"
|
5
4
|
require "active_support/encrypted_file"
|
6
5
|
|
7
6
|
module Rails
|
@@ -16,10 +15,10 @@ module Rails
|
|
16
15
|
|
17
16
|
private
|
18
17
|
def encrypted_file_template
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
<<~YAML
|
19
|
+
# aws:
|
20
|
+
# access_key_id: 123
|
21
|
+
# secret_access_key: 345
|
23
22
|
|
24
23
|
YAML
|
25
24
|
end
|
@@ -88,7 +88,7 @@ task default: :test
|
|
88
88
|
|
89
89
|
PASSTHROUGH_OPTIONS = [
|
90
90
|
:skip_active_record, :skip_active_storage, :skip_action_mailer, :skip_javascript, :skip_action_cable, :skip_sprockets, :database,
|
91
|
-
:
|
91
|
+
:api, :quiet, :pretend, :skip
|
92
92
|
]
|
93
93
|
|
94
94
|
def generate_test_dummy(force = false)
|
@@ -98,6 +98,7 @@ task default: :test
|
|
98
98
|
opts[:skip_listen] = true
|
99
99
|
opts[:skip_git] = true
|
100
100
|
opts[:skip_turbolinks] = true
|
101
|
+
opts[:skip_webpack_install] = true
|
101
102
|
opts[:dummy_app] = true
|
102
103
|
|
103
104
|
invoke Rails::Generators::AppGenerator,
|
@@ -113,7 +114,7 @@ task default: :test
|
|
113
114
|
end
|
114
115
|
|
115
116
|
def test_dummy_assets
|
116
|
-
template "rails/javascripts.js", "#{dummy_path}/app/
|
117
|
+
template "rails/javascripts.js", "#{dummy_path}/app/javascript/packs/application.js", force: true
|
117
118
|
template "rails/stylesheets.css", "#{dummy_path}/app/assets/stylesheets/application.css", force: true
|
118
119
|
template "rails/dummy_manifest.js", "#{dummy_path}/app/assets/config/manifest.js", force: true
|
119
120
|
end
|
@@ -143,17 +144,6 @@ task default: :test
|
|
143
144
|
end
|
144
145
|
end
|
145
146
|
|
146
|
-
def javascripts
|
147
|
-
return if options.skip_javascript?
|
148
|
-
|
149
|
-
if mountable?
|
150
|
-
template "rails/javascripts.js",
|
151
|
-
"app/assets/javascripts/#{namespaced_name}/application.js"
|
152
|
-
elsif full?
|
153
|
-
empty_directory_with_keep_file "app/assets/javascripts/#{namespaced_name}"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
147
|
def bin(force = false)
|
158
148
|
bin_file = engine? ? "bin/rails.tt" : "bin/test.tt"
|
159
149
|
template bin_file, force: force do |content|
|
@@ -235,10 +225,6 @@ task default: :test
|
|
235
225
|
build(:stylesheets) unless api?
|
236
226
|
end
|
237
227
|
|
238
|
-
def create_javascript_files
|
239
|
-
build(:javascripts) unless api?
|
240
|
-
end
|
241
|
-
|
242
228
|
def create_bin_files
|
243
229
|
build(:bin)
|
244
230
|
end
|
@@ -262,16 +248,6 @@ task default: :test
|
|
262
248
|
|
263
249
|
public_task :apply_rails_template
|
264
250
|
|
265
|
-
def run_after_bundle_callbacks
|
266
|
-
unless @after_bundle_callbacks.empty?
|
267
|
-
ActiveSupport::Deprecation.warn("`after_bundle` is deprecated and will be removed in the next version of Rails. ")
|
268
|
-
end
|
269
|
-
|
270
|
-
@after_bundle_callbacks.each do |callback|
|
271
|
-
callback.call
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
251
|
def name
|
276
252
|
@name ||= begin
|
277
253
|
# same as ActiveSupport::Inflector#underscore except not replacing '-'
|
@@ -348,9 +324,9 @@ task default: :test
|
|
348
324
|
def wrap_in_modules(unwrapped_code)
|
349
325
|
unwrapped_code = "#{unwrapped_code}".strip.gsub(/\s$\n/, "")
|
350
326
|
modules.reverse.inject(unwrapped_code) do |content, mod|
|
351
|
-
str = "module #{mod}\n"
|
352
|
-
str
|
353
|
-
str
|
327
|
+
str = +"module #{mod}\n"
|
328
|
+
str << content.lines.map { |line| " #{line}" }.join
|
329
|
+
str << (content.present? ? "\nend" : "end")
|
354
330
|
end
|
355
331
|
end
|
356
332
|
|
@@ -385,11 +361,11 @@ task default: :test
|
|
385
361
|
end
|
386
362
|
|
387
363
|
def valid_const?
|
388
|
-
if
|
364
|
+
if /-\d/.match?(original_name)
|
389
365
|
raise Error, "Invalid plugin name #{original_name}. Please give a name which does not contain a namespace starting with numeric characters."
|
390
|
-
elsif
|
366
|
+
elsif /[^\w-]+/.match?(original_name)
|
391
367
|
raise Error, "Invalid plugin name #{original_name}. Please give a name which uses only alphabetic, numeric, \"_\" or \"-\" characters."
|
392
|
-
elsif
|
368
|
+
elsif /^\d/.match?(camelized)
|
393
369
|
raise Error, "Invalid plugin name #{original_name}. Please give a name which does not start with numbers."
|
394
370
|
elsif RESERVED_NAMES.include?(name)
|
395
371
|
raise Error, "Invalid plugin name #{original_name}. Please give a " \
|