railties 5.2.8.1 → 6.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +405 -145
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +38 -32
- data/README.rdoc +3 -3
- data/lib/minitest/rails_plugin.rb +7 -11
- data/lib/rails/all.rb +4 -0
- data/lib/rails/api/generator.rb +2 -1
- data/lib/rails/api/task.rb +18 -1
- data/lib/rails/app_loader.rb +2 -2
- data/lib/rails/app_updater.rb +3 -1
- data/lib/rails/application/bootstrap.rb +4 -12
- data/lib/rails/application/configuration.rb +118 -13
- data/lib/rails/application/default_middleware_stack.rb +4 -2
- data/lib/rails/application/dummy_erb_compiler.rb +18 -0
- data/lib/rails/application/finisher.rb +54 -0
- data/lib/rails/application/routes_reloader.rb +0 -1
- data/lib/rails/application.rb +87 -39
- data/lib/rails/application_controller.rb +0 -1
- data/lib/rails/autoloaders.rb +48 -0
- data/lib/rails/backtrace_cleaner.rb +5 -17
- data/lib/rails/code_statistics.rb +5 -3
- data/lib/rails/command/base.rb +12 -4
- data/lib/rails/command/behavior.rb +8 -49
- data/lib/rails/command/environment_argument.rb +8 -15
- data/lib/rails/command/spellchecker.rb +57 -0
- data/lib/rails/command.rb +11 -10
- 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 +14 -15
- data/lib/rails/engine/configuration.rb +5 -2
- data/lib/rails/engine.rb +25 -18
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators/actions/create_migration.rb +0 -1
- data/lib/rails/generators/actions.rb +52 -40
- data/lib/rails/generators/app_base.rb +54 -95
- data/lib/rails/generators/app_name.rb +50 -0
- data/lib/rails/generators/base.rb +3 -3
- data/lib/rails/generators/database.rb +58 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -2
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -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/erb.rb +0 -1
- data/lib/rails/generators/generated_attribute.rb +53 -28
- data/lib/rails/generators/migration.rb +1 -2
- data/lib/rails/generators/model_helpers.rb +8 -1
- data/lib/rails/generators/named_base.rb +2 -6
- data/lib/rails/generators/rails/app/app_generator.rb +39 -75
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +8 -11
- 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 +14 -6
- 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 +4 -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 +8 -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 +10 -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 +10 -7
- data/lib/rails/generators/rails/generator/generator_generator.rb +0 -1
- data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +9 -34
- 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 +2 -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 +13 -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/generator/generator_generator.rb +0 -1
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +5 -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 -4
- data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
- data/lib/rails/generators/testing/behaviour.rb +3 -1
- data/lib/rails/generators.rb +11 -11
- data/lib/rails/info.rb +3 -3
- data/lib/rails/info_controller.rb +1 -2
- data/lib/rails/mailers_controller.rb +7 -4
- data/lib/rails/paths.rb +18 -10
- data/lib/rails/rack/logger.rb +1 -2
- data/lib/rails/railtie/configurable.rb +0 -1
- data/lib/rails/railtie/configuration.rb +0 -1
- data/lib/rails/railtie.rb +2 -3
- 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/annotations.rake +9 -9
- data/lib/rails/tasks/dev.rake +5 -4
- data/lib/rails/tasks/framework.rake +6 -2
- 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 +69 -0
- data/lib/rails/tasks.rb +1 -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 +14 -6
- data/lib/rails/test_unit/testing.rake +1 -1
- data/lib/rails.rb +5 -0
- metadata +35 -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
data/lib/rails/generators/erb.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/time"
|
4
|
+
require "active_support/deprecation"
|
4
5
|
|
5
6
|
module Rails
|
6
7
|
module Generators
|
@@ -38,24 +39,29 @@ module Rails
|
|
38
39
|
end
|
39
40
|
|
40
41
|
private
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
42
|
+
# parse possible attribute options like :limit for string/text/binary/integer, :precision/:scale for decimals or :polymorphic for references/belongs_to
|
43
|
+
# when declaring options curly brackets should be used
|
44
|
+
def parse_type_and_options(type)
|
45
|
+
case type
|
46
|
+
when /(string|text|binary|integer)\{(\d+)\}/
|
47
|
+
return $1, limit: $2.to_i
|
48
|
+
when /decimal\{(\d+)[,.-](\d+)\}/
|
49
|
+
return :decimal, precision: $1.to_i, scale: $2.to_i
|
50
|
+
when /(references|belongs_to)\{(.+)\}/
|
51
|
+
type = $1
|
52
|
+
provided_options = $2.split(/[,.-]/)
|
53
|
+
options = Hash[provided_options.map { |opt| [opt.to_sym, true] }]
|
54
|
+
|
55
|
+
if options[:required]
|
56
|
+
ActiveSupport::Deprecation.warn("Passing {required} option has no effect on the model generator. It will be removed in Rails 6.1.\n")
|
57
|
+
options.delete(:required)
|
58
|
+
end
|
59
|
+
|
60
|
+
return type, options
|
61
|
+
else
|
62
|
+
return type, {}
|
63
|
+
end
|
57
64
|
end
|
58
|
-
end
|
59
65
|
end
|
60
66
|
|
61
67
|
def initialize(name, type = nil, index_type = false, attr_options = {})
|
@@ -68,13 +74,15 @@ module Rails
|
|
68
74
|
|
69
75
|
def field_type
|
70
76
|
@field_type ||= case type
|
71
|
-
when :integer
|
72
|
-
when :float, :decimal
|
73
|
-
when :time
|
74
|
-
when :datetime, :timestamp
|
75
|
-
when :date
|
76
|
-
when :text
|
77
|
-
when :
|
77
|
+
when :integer then :number_field
|
78
|
+
when :float, :decimal then :text_field
|
79
|
+
when :time then :time_select
|
80
|
+
when :datetime, :timestamp then :datetime_select
|
81
|
+
when :date then :date_select
|
82
|
+
when :text then :text_area
|
83
|
+
when :rich_text then :rich_text_area
|
84
|
+
when :boolean then :check_box
|
85
|
+
when :attachment, :attachments then :file_field
|
78
86
|
else
|
79
87
|
:text_field
|
80
88
|
end
|
@@ -90,7 +98,9 @@ module Rails
|
|
90
98
|
when :string then name == "type" ? "" : "MyString"
|
91
99
|
when :text then "MyText"
|
92
100
|
when :boolean then false
|
93
|
-
when :references, :belongs_to
|
101
|
+
when :references, :belongs_to,
|
102
|
+
:attachment, :attachments,
|
103
|
+
:rich_text then nil
|
94
104
|
else
|
95
105
|
""
|
96
106
|
end
|
@@ -133,7 +143,7 @@ module Rails
|
|
133
143
|
end
|
134
144
|
|
135
145
|
def required?
|
136
|
-
|
146
|
+
reference? && Rails.application.config.active_record.belongs_to_required_by_default
|
137
147
|
end
|
138
148
|
|
139
149
|
def has_index?
|
@@ -152,8 +162,24 @@ module Rails
|
|
152
162
|
type == :token
|
153
163
|
end
|
154
164
|
|
165
|
+
def rich_text?
|
166
|
+
type == :rich_text
|
167
|
+
end
|
168
|
+
|
169
|
+
def attachment?
|
170
|
+
type == :attachment
|
171
|
+
end
|
172
|
+
|
173
|
+
def attachments?
|
174
|
+
type == :attachments
|
175
|
+
end
|
176
|
+
|
177
|
+
def virtual?
|
178
|
+
rich_text? || attachment? || attachments?
|
179
|
+
end
|
180
|
+
|
155
181
|
def inject_options
|
156
|
-
"".
|
182
|
+
(+"").tap { |s| options_for_migration.each { |k, v| s << ", #{k}: #{v.inspect}" } }
|
157
183
|
end
|
158
184
|
|
159
185
|
def inject_index_options
|
@@ -163,7 +189,6 @@ module Rails
|
|
163
189
|
def options_for_migration
|
164
190
|
@attr_options.dup.tap do |options|
|
165
191
|
if required?
|
166
|
-
options.delete(:required)
|
167
192
|
options[:null] = false
|
168
193
|
end
|
169
194
|
|
@@ -63,8 +63,7 @@ module Rails
|
|
63
63
|
numbered_destination = File.join(dir, ["%migration_number%", base].join("_"))
|
64
64
|
|
65
65
|
create_migration numbered_destination, nil, config do
|
66
|
-
|
67
|
-
if match && match[:version] >= "2.2.0" # Ruby 2.6+
|
66
|
+
if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
|
68
67
|
ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(context)
|
69
68
|
else
|
70
69
|
ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
|
@@ -7,6 +7,10 @@ module Rails
|
|
7
7
|
module ModelHelpers # :nodoc:
|
8
8
|
PLURAL_MODEL_NAME_WARN_MESSAGE = "[WARNING] The model name '%s' was recognized as a plural, using the singular '%s' instead. " \
|
9
9
|
"Override with --force-plural or setup custom inflection rules for this noun before running the generator."
|
10
|
+
IRREGULAR_MODEL_NAME_WARN_MESSAGE = <<~WARNING
|
11
|
+
[WARNING] Rails cannot recover singular form from its plural form '%s'.
|
12
|
+
Please setup custom inflection rules for this noun before running the generator in config/initializers/inflections.rb.
|
13
|
+
WARNING
|
10
14
|
mattr_accessor :skip_warn
|
11
15
|
|
12
16
|
def self.included(base) #:nodoc:
|
@@ -19,11 +23,14 @@ module Rails
|
|
19
23
|
singular = name.singularize
|
20
24
|
unless ModelHelpers.skip_warn
|
21
25
|
say PLURAL_MODEL_NAME_WARN_MESSAGE % [name, singular]
|
22
|
-
ModelHelpers.skip_warn = true
|
23
26
|
end
|
24
27
|
name.replace singular
|
25
28
|
assign_names!(name)
|
26
29
|
end
|
30
|
+
if name.singularize != name.pluralize.singularize && ! ModelHelpers.skip_warn
|
31
|
+
say IRREGULAR_MODEL_NAME_WARN_MESSAGE % [name.pluralize]
|
32
|
+
end
|
33
|
+
ModelHelpers.skip_warn = true
|
27
34
|
end
|
28
35
|
end
|
29
36
|
end
|
@@ -31,12 +31,8 @@ module Rails
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
# TODO Change this to private once we've dropped Ruby 2.2 support.
|
35
|
-
# Workaround for Ruby 2.2 "private attribute?" warning.
|
36
|
-
protected
|
37
|
-
attr_reader :file_name
|
38
|
-
|
39
34
|
private
|
35
|
+
attr_reader :file_name
|
40
36
|
|
41
37
|
# FIXME: We are avoiding to use alias because a bug on thor that make
|
42
38
|
# this method public and add it to the task list.
|
@@ -217,7 +213,7 @@ module Rails
|
|
217
213
|
#
|
218
214
|
def self.check_class_collision(options = {}) # :doc:
|
219
215
|
define_method :check_class_collision do
|
220
|
-
name = if respond_to?(:controller_class_name) # for ResourceHelpers
|
216
|
+
name = if respond_to?(:controller_class_name, true) # for ResourceHelpers
|
221
217
|
controller_class_name
|
222
218
|
else
|
223
219
|
class_name
|
@@ -21,7 +21,6 @@ module Rails
|
|
21
21
|
RUBY
|
22
22
|
end
|
23
23
|
|
24
|
-
# TODO: Remove once this is fully in place
|
25
24
|
def method_missing(meth, *args, &block)
|
26
25
|
@generator.send(meth, *args, &block)
|
27
26
|
end
|
@@ -69,7 +68,7 @@ module Rails
|
|
69
68
|
|
70
69
|
def version_control
|
71
70
|
if !options[:skip_git] && !options[:pretend]
|
72
|
-
run "git init", capture: options[:quiet]
|
71
|
+
run "git init", capture: options[:quiet], abort_on_failure: false
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
@@ -80,8 +79,7 @@ module Rails
|
|
80
79
|
def app
|
81
80
|
directory "app"
|
82
81
|
|
83
|
-
|
84
|
-
empty_directory_with_keep_file "app/assets/javascripts/channels" unless options[:skip_action_cable]
|
82
|
+
empty_directory_with_keep_file "app/assets/images"
|
85
83
|
|
86
84
|
keep_file "app/controllers/concerns"
|
87
85
|
keep_file "app/models/concerns"
|
@@ -95,11 +93,9 @@ module Rails
|
|
95
93
|
end
|
96
94
|
|
97
95
|
def bin_when_updating
|
98
|
-
bin_yarn_exist = File.exist?("bin/yarn")
|
99
|
-
|
100
96
|
bin
|
101
97
|
|
102
|
-
if options[:
|
98
|
+
if options[:skip_javascript]
|
103
99
|
remove_file "bin/yarn"
|
104
100
|
end
|
105
101
|
end
|
@@ -159,10 +155,6 @@ module Rails
|
|
159
155
|
remove_file "config/initializers/cookies_serializer.rb"
|
160
156
|
end
|
161
157
|
|
162
|
-
unless assets_config_exist
|
163
|
-
remove_file "config/initializers/assets.rb"
|
164
|
-
end
|
165
|
-
|
166
158
|
unless csp_config_exist
|
167
159
|
remove_file "config/initializers/content_security_policy.rb"
|
168
160
|
end
|
@@ -221,6 +213,7 @@ module Rails
|
|
221
213
|
empty_directory_with_keep_file "test/helpers"
|
222
214
|
empty_directory_with_keep_file "test/integration"
|
223
215
|
|
216
|
+
template "test/channels/application_cable/connection_test.rb"
|
224
217
|
template "test/test_helper.rb"
|
225
218
|
end
|
226
219
|
|
@@ -250,14 +243,13 @@ module Rails
|
|
250
243
|
# We need to store the RAILS_DEV_PATH in a constant, otherwise the path
|
251
244
|
# can change in Ruby 1.8.7 when we FileUtils.cd.
|
252
245
|
RAILS_DEV_PATH = File.expand_path("../../../../../..", __dir__)
|
253
|
-
RESERVED_NAMES = %w[application destroy plugin runner test]
|
254
246
|
|
255
247
|
class AppGenerator < AppBase # :nodoc:
|
256
248
|
WEBPACKS = %w( react vue angular elm stimulus )
|
257
249
|
|
258
250
|
add_shared_options_for "application"
|
259
251
|
|
260
|
-
# Add
|
252
|
+
# Add rails command options
|
261
253
|
class_option :version, type: :boolean, aliases: "-v", group: :rails,
|
262
254
|
desc: "Show Rails version number and quit"
|
263
255
|
|
@@ -267,21 +259,26 @@ module Rails
|
|
267
259
|
class_option :skip_bundle, type: :boolean, aliases: "-B", default: false,
|
268
260
|
desc: "Don't run bundle install"
|
269
261
|
|
270
|
-
class_option :webpack, type: :string, default: nil,
|
271
|
-
desc: "Preconfigure
|
262
|
+
class_option :webpack, type: :string, aliases: "--webpacker", default: nil,
|
263
|
+
desc: "Preconfigure Webpack with a particular framework (options: #{WEBPACKS.join(", ")})"
|
264
|
+
|
265
|
+
class_option :skip_webpack_install, type: :boolean, default: false,
|
266
|
+
desc: "Don't run Webpack install"
|
272
267
|
|
273
268
|
def initialize(*args)
|
274
269
|
super
|
275
270
|
|
276
271
|
if !options[:skip_active_record] && !DATABASES.include?(options[:database])
|
277
|
-
raise Error, "Invalid value for --database option. Supported
|
272
|
+
raise Error, "Invalid value for --database option. Supported preconfigurations are: #{DATABASES.join(", ")}."
|
278
273
|
end
|
279
274
|
|
280
275
|
# Force sprockets and yarn to be skipped when generating API only apps.
|
281
276
|
# Can't modify options hash as it's frozen by default.
|
282
277
|
if options[:api]
|
283
|
-
self.options = options.merge(skip_sprockets: true, skip_javascript: true
|
278
|
+
self.options = options.merge(skip_sprockets: true, skip_javascript: true).freeze
|
284
279
|
end
|
280
|
+
|
281
|
+
@after_bundle_callbacks = []
|
285
282
|
end
|
286
283
|
|
287
284
|
public_task :set_default_accessors!
|
@@ -295,7 +292,7 @@ module Rails
|
|
295
292
|
build(:gitignore) unless options[:skip_git]
|
296
293
|
build(:gemfile) unless options[:skip_gemfile]
|
297
294
|
build(:version_control)
|
298
|
-
build(:package_json) unless options[:
|
295
|
+
build(:package_json) unless options[:skip_javascript]
|
299
296
|
end
|
300
297
|
|
301
298
|
def create_app_files
|
@@ -311,6 +308,13 @@ module Rails
|
|
311
308
|
end
|
312
309
|
remove_task :update_bin_files
|
313
310
|
|
311
|
+
def update_active_storage
|
312
|
+
unless skip_active_storage?
|
313
|
+
rails_command "active_storage:update"
|
314
|
+
end
|
315
|
+
end
|
316
|
+
remove_task :update_active_storage
|
317
|
+
|
314
318
|
def create_config_files
|
315
319
|
build(:config)
|
316
320
|
end
|
@@ -329,7 +333,7 @@ module Rails
|
|
329
333
|
end
|
330
334
|
|
331
335
|
def display_upgrade_guide_info
|
332
|
-
say "\nAfter this, check Rails upgrade guide at
|
336
|
+
say "\nAfter this, check Rails upgrade guide at https://guides.rubyonrails.org/upgrading_ruby_on_rails.html for more details about upgrading your app."
|
333
337
|
end
|
334
338
|
remove_task :display_upgrade_guide_info
|
335
339
|
|
@@ -417,7 +421,7 @@ module Rails
|
|
417
421
|
|
418
422
|
def delete_js_folder_skipping_javascript
|
419
423
|
if options[:skip_javascript]
|
420
|
-
remove_dir "app/
|
424
|
+
remove_dir "app/javascript"
|
421
425
|
end
|
422
426
|
end
|
423
427
|
|
@@ -444,8 +448,9 @@ module Rails
|
|
444
448
|
|
445
449
|
def delete_action_cable_files_skipping_action_cable
|
446
450
|
if options[:skip_action_cable]
|
447
|
-
|
451
|
+
remove_dir "app/javascript/channels"
|
448
452
|
remove_dir "app/channels"
|
453
|
+
remove_dir "test/channels"
|
449
454
|
end
|
450
455
|
end
|
451
456
|
|
@@ -464,12 +469,12 @@ module Rails
|
|
464
469
|
|
465
470
|
def delete_new_framework_defaults
|
466
471
|
unless options[:update]
|
467
|
-
remove_file "config/initializers/
|
472
|
+
remove_file "config/initializers/new_framework_defaults_6_0.rb"
|
468
473
|
end
|
469
474
|
end
|
470
475
|
|
471
|
-
def
|
472
|
-
remove_file "bin/yarn" if options[:
|
476
|
+
def delete_bin_yarn
|
477
|
+
remove_file "bin/yarn" if options[:skip_javascript]
|
473
478
|
end
|
474
479
|
|
475
480
|
def finish_template
|
@@ -477,7 +482,8 @@ module Rails
|
|
477
482
|
end
|
478
483
|
|
479
484
|
public_task :apply_rails_template, :run_bundle
|
480
|
-
public_task :
|
485
|
+
public_task :generate_bundler_binstub, :generate_spring_binstubs
|
486
|
+
public_task :run_webpack
|
481
487
|
|
482
488
|
def run_after_bundle_callbacks
|
483
489
|
@after_bundle_callbacks.each(&:call)
|
@@ -488,60 +494,19 @@ module Rails
|
|
488
494
|
end
|
489
495
|
|
490
496
|
private
|
491
|
-
|
492
497
|
# Define file as an alias to create_file for backwards compatibility.
|
493
498
|
def file(*args, &block)
|
494
499
|
create_file(*args, &block)
|
495
500
|
end
|
496
501
|
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
def defined_app_const_base
|
506
|
-
Rails.respond_to?(:application) && defined?(Rails::Application) &&
|
507
|
-
Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "")
|
508
|
-
end
|
509
|
-
|
510
|
-
alias :defined_app_const_base? :defined_app_const_base
|
511
|
-
|
512
|
-
def app_const_base
|
513
|
-
@app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, "_").squeeze("_").camelize
|
514
|
-
end
|
515
|
-
alias :camelized :app_const_base
|
516
|
-
|
517
|
-
def app_const
|
518
|
-
@app_const ||= "#{app_const_base}::Application"
|
519
|
-
end
|
520
|
-
|
521
|
-
def valid_const?
|
522
|
-
if app_const =~ /^\d/
|
523
|
-
raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
|
524
|
-
elsif RESERVED_NAMES.include?(app_name)
|
525
|
-
raise Error, "Invalid application name #{app_name}. Please give a " \
|
526
|
-
"name which does not match one of the reserved rails " \
|
527
|
-
"words: #{RESERVED_NAMES.join(", ")}"
|
528
|
-
elsif Object.const_defined?(app_const_base)
|
529
|
-
raise Error, "Invalid application name #{app_name}, constant #{app_const_base} is already in use. Please choose another application name."
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
def mysql_socket
|
534
|
-
@mysql_socket ||= [
|
535
|
-
"/tmp/mysql.sock", # default
|
536
|
-
"/var/run/mysqld/mysqld.sock", # debian/gentoo
|
537
|
-
"/var/tmp/mysql.sock", # freebsd
|
538
|
-
"/var/lib/mysql/mysql.sock", # fedora
|
539
|
-
"/opt/local/lib/mysql/mysql.sock", # fedora
|
540
|
-
"/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
|
541
|
-
"/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
|
542
|
-
"/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
|
543
|
-
"/opt/lampp/var/mysql/mysql.sock" # xampp for linux
|
544
|
-
].find { |f| File.exist?(f) } unless Gem.win_platform?
|
502
|
+
# Registers a callback to be executed after bundle and spring binstubs
|
503
|
+
# have run.
|
504
|
+
#
|
505
|
+
# after_bundle do
|
506
|
+
# git add: '.'
|
507
|
+
# end
|
508
|
+
def after_bundle(&block) # :doc:
|
509
|
+
@after_bundle_callbacks << block
|
545
510
|
end
|
546
511
|
|
547
512
|
def get_builder_class
|
@@ -573,7 +538,6 @@ module Rails
|
|
573
538
|
end
|
574
539
|
|
575
540
|
private
|
576
|
-
|
577
541
|
def handle_version_request!(argument)
|
578
542
|
if ["--version", "-v"].include?(argument)
|
579
543
|
require "rails/version"
|
@@ -18,20 +18,17 @@ ruby <%= "'#{RUBY_VERSION}'" -%>
|
|
18
18
|
<% end -%>
|
19
19
|
<% end -%>
|
20
20
|
|
21
|
-
# Use
|
21
|
+
# Use Active Model has_secure_password
|
22
22
|
# gem 'bcrypt', '~> 3.1.7'
|
23
23
|
<% unless skip_active_storage? -%>
|
24
24
|
|
25
|
-
# Use
|
26
|
-
# gem '
|
25
|
+
# Use Active Storage variant
|
26
|
+
# gem 'image_processing', '~> 1.2'
|
27
27
|
<% end -%>
|
28
28
|
|
29
|
-
# Use Capistrano for deployment
|
30
|
-
# gem 'capistrano-rails', group: :development
|
31
|
-
|
32
29
|
<% if depend_on_bootsnap? -%>
|
33
30
|
# Reduces boot times through caching; required in config/boot.rb
|
34
|
-
gem 'bootsnap', '>= 1.
|
31
|
+
gem 'bootsnap', '>= 1.4.2', require: false
|
35
32
|
|
36
33
|
<%- end -%>
|
37
34
|
<%- if options.api? -%>
|
@@ -56,7 +53,7 @@ group :development do
|
|
56
53
|
<%- end -%>
|
57
54
|
<%- end -%>
|
58
55
|
<% if depend_on_listen? -%>
|
59
|
-
gem 'listen', '
|
56
|
+
gem 'listen', '~> 3.2'
|
60
57
|
<% end -%>
|
61
58
|
<% if spring_install? -%>
|
62
59
|
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
@@ -72,10 +69,10 @@ group :test do
|
|
72
69
|
# Adds support for Capybara system testing and selenium driver
|
73
70
|
gem 'capybara', '>= 2.15'
|
74
71
|
gem 'selenium-webdriver'
|
75
|
-
# Easy installation and use of
|
76
|
-
gem '
|
72
|
+
# Easy installation and use of web drivers to run system tests with browsers
|
73
|
+
gem 'webdrivers'
|
77
74
|
end
|
78
|
-
<%- end -%>
|
79
75
|
|
76
|
+
<%- end -%>
|
80
77
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
81
78
|
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
@@ -1,13 +1,6 @@
|
|
1
1
|
// Action Cable provides the framework to deal with WebSockets in Rails.
|
2
2
|
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
|
3
|
-
//
|
4
|
-
//= require action_cable
|
5
|
-
//= require_self
|
6
|
-
//= require_tree ./channels
|
7
3
|
|
8
|
-
|
9
|
-
this.App || (this.App = {});
|
4
|
+
import { createConsumer } from "@rails/actioncable"
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
}).call(this);
|
6
|
+
export default createConsumer()
|
@@ -0,0 +1,23 @@
|
|
1
|
+
// This file is automatically compiled by Webpack, along with any other files
|
2
|
+
// present in this directory. You're encouraged to place your actual application logic in
|
3
|
+
// a relevant structure within app/javascript and only use these pack files to reference
|
4
|
+
// that code so it'll be compiled.
|
5
|
+
|
6
|
+
require("@rails/ujs").start()
|
7
|
+
<%- unless options[:skip_turbolinks] -%>
|
8
|
+
require("turbolinks").start()
|
9
|
+
<%- end -%>
|
10
|
+
<%- unless skip_active_storage? -%>
|
11
|
+
require("@rails/activestorage").start()
|
12
|
+
<%- end -%>
|
13
|
+
<%- unless options[:skip_action_cable] -%>
|
14
|
+
require("channels")
|
15
|
+
<%- end -%>
|
16
|
+
|
17
|
+
|
18
|
+
// Uncomment to copy all static images under ../images to the output folder and reference
|
19
|
+
// them with the image_pack_tag helper in views (e.g <%%= image_pack_tag 'rails.png' %>)
|
20
|
+
// or the `imagePath` JavaScript helper below.
|
21
|
+
//
|
22
|
+
// const images = require.context('../images', true)
|
23
|
+
// const imagePath = (name) => images(name, true)
|
@@ -1,2 +1,7 @@
|
|
1
1
|
class ApplicationJob < ActiveJob::Base
|
2
|
+
# Automatically retry jobs that encountered a deadlock
|
3
|
+
# retry_on ActiveRecord::Deadlocked
|
4
|
+
|
5
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
+
# discard_on ActiveJob::DeserializationError
|
2
7
|
end
|
@@ -9,11 +9,11 @@
|
|
9
9
|
<%%= stylesheet_link_tag 'application', media: 'all' %>
|
10
10
|
<%- else -%>
|
11
11
|
<%- unless options[:skip_turbolinks] -%>
|
12
|
-
<%%= stylesheet_link_tag
|
13
|
-
<%%=
|
12
|
+
<%%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
|
13
|
+
<%%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
|
14
14
|
<%- else -%>
|
15
|
-
<%%= stylesheet_link_tag
|
16
|
-
<%%=
|
15
|
+
<%%= stylesheet_link_tag 'application', media: 'all' %>
|
16
|
+
<%%= javascript_pack_tag 'application' %>
|
17
17
|
<%- end -%>
|
18
18
|
<%- end -%>
|
19
19
|
</head>
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
include FileUtils
|
3
2
|
|
4
3
|
# path to your application root.
|
5
4
|
APP_ROOT = File.expand_path('..', __dir__)
|
@@ -8,27 +7,28 @@ def system!(*args)
|
|
8
7
|
system(*args) || abort("\n== Command #{args} failed ==")
|
9
8
|
end
|
10
9
|
|
11
|
-
chdir APP_ROOT do
|
12
|
-
# This script is a
|
10
|
+
FileUtils.chdir APP_ROOT do
|
11
|
+
# This script is a way to setup or update your development environment automatically.
|
12
|
+
# This script is idempotent, so that you can run it at anytime and get an expectable outcome.
|
13
13
|
# Add necessary setup steps to this file.
|
14
14
|
|
15
15
|
puts '== Installing dependencies =='
|
16
16
|
system! 'gem install bundler --conservative'
|
17
17
|
system('bundle check') || system!('bundle install')
|
18
|
-
<% unless options.
|
18
|
+
<% unless options.skip_javascript? -%>
|
19
19
|
|
20
|
-
# Install JavaScript dependencies
|
20
|
+
# Install JavaScript dependencies
|
21
21
|
# system('bin/yarn')
|
22
22
|
<% end -%>
|
23
23
|
<% unless options.skip_active_record? -%>
|
24
24
|
|
25
25
|
# puts "\n== Copying sample files =="
|
26
26
|
# unless File.exist?('config/database.yml')
|
27
|
-
# cp 'config/database.yml.sample', 'config/database.yml'
|
27
|
+
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
|
28
28
|
# end
|
29
29
|
|
30
30
|
puts "\n== Preparing database =="
|
31
|
-
system! 'bin/rails db:
|
31
|
+
system! 'bin/rails db:prepare'
|
32
32
|
<% end -%>
|
33
33
|
|
34
34
|
puts "\n== Removing old logs and tempfiles =="
|
@@ -11,6 +11,8 @@ require "active_job/railtie"
|
|
11
11
|
<%= comment_if :skip_active_storage %>require "active_storage/engine"
|
12
12
|
require "action_controller/railtie"
|
13
13
|
<%= comment_if :skip_action_mailer %>require "action_mailer/railtie"
|
14
|
+
<%= comment_if :skip_action_mailbox %>require "action_mailbox/engine"
|
15
|
+
<%= comment_if :skip_action_text %>require "action_text/engine"
|
14
16
|
require "action_view/railtie"
|
15
17
|
<%= comment_if :skip_action_cable %>require "action_cable/engine"
|
16
18
|
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
|
@@ -24,12 +24,12 @@ test:
|
|
24
24
|
<<: *default
|
25
25
|
database: <%= app_name %>_test
|
26
26
|
|
27
|
-
# As with config/
|
27
|
+
# As with config/credentials.yml, you never want to store sensitive information,
|
28
28
|
# like your database password, in your source code. If your source code is
|
29
29
|
# ever seen by anyone, they now have access to your database.
|
30
30
|
#
|
31
31
|
# Instead, provide the password as a unix environment variable when you boot
|
32
|
-
# the app. Read
|
32
|
+
# the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
|
33
33
|
# for a full rundown on how to provide these environment variables in a
|
34
34
|
# production deployment.
|
35
35
|
#
|