railties 5.2.3.rc1 → 6.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of railties might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +190 -130
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +35 -28
- data/README.rdoc +1 -1
- data/lib/minitest/rails_plugin.rb +6 -10
- 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 +1 -1
- data/lib/rails/app_updater.rb +3 -1
- data/lib/rails/application.rb +21 -45
- data/lib/rails/application/configuration.rb +54 -12
- data/lib/rails/application/default_middleware_stack.rb +2 -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/actions.rb +0 -10
- data/lib/rails/command/base.rb +1 -1
- data/lib/rails/command/behavior.rb +4 -46
- data/lib/rails/command/environment_argument.rb +1 -11
- data/lib/rails/command/spellchecker.rb +58 -0
- data/lib/rails/commands/credentials/USAGE +19 -1
- data/lib/rails/commands/credentials/credentials_command.rb +42 -23
- data/lib/rails/commands/db/system/change/change_command.rb +20 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +2 -2
- data/lib/rails/commands/dev/dev_command.rb +17 -0
- data/lib/rails/commands/encrypted/encrypted_command.rb +2 -3
- data/lib/rails/commands/help/help_command.rb +1 -1
- data/lib/rails/commands/initializers/initializers_command.rb +16 -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 +6 -6
- 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 +109 -48
- data/lib/rails/configuration.rb +1 -7
- data/lib/rails/engine/configuration.rb +3 -1
- data/lib/rails/gem_version.rb +4 -4
- data/lib/rails/generators.rb +11 -12
- data/lib/rails/generators/actions.rb +48 -37
- data/lib/rails/generators/app_base.rb +56 -94
- data/lib/rails/generators/app_name.rb +50 -0
- data/lib/rails/generators/database.rb +57 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -1
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +1 -1
- data/lib/rails/generators/generated_attribute.rb +17 -17
- 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 +3 -6
- 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 +15 -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 +4 -5
- data/lib/rails/generators/rails/app/templates/bin/update.tt +6 -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/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/sqlserver.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -2
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +5 -12
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -2
- 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 +4 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +33 -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 +3 -2
- 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/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 -8
- 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 +55 -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 -18
- 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/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/scaffold/scaffold_generator.rb +1 -1
- 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 +1 -1
- 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 +125 -117
- 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 +1 -0
- data/lib/rails/tasks/yarn.rake +1 -1
- 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 +27 -21
- data/lib/rails/commands/encrypted/USAGE +0 -28
- 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/config/initializers/new_framework_defaults_5_2.rb.tt +0 -38
- data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
module AppName # :nodoc:
|
6
|
+
RESERVED_NAMES = %w(application destroy plugin runner test)
|
7
|
+
|
8
|
+
private
|
9
|
+
def app_name
|
10
|
+
@app_name ||= original_app_name.tr("-", "_")
|
11
|
+
end
|
12
|
+
|
13
|
+
def original_app_name
|
14
|
+
@original_app_name ||= (defined_app_const_base? ? defined_app_name : File.basename(destination_root)).tr('\\', "").tr(". ", "_")
|
15
|
+
end
|
16
|
+
|
17
|
+
def defined_app_name
|
18
|
+
defined_app_const_base.underscore
|
19
|
+
end
|
20
|
+
|
21
|
+
def defined_app_const_base
|
22
|
+
Rails.respond_to?(:application) && defined?(Rails::Application) &&
|
23
|
+
Rails.application.is_a?(Rails::Application) && Rails.application.class.name.chomp("::Application")
|
24
|
+
end
|
25
|
+
|
26
|
+
alias :defined_app_const_base? :defined_app_const_base
|
27
|
+
|
28
|
+
def app_const_base
|
29
|
+
@app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, "_").squeeze("_").camelize
|
30
|
+
end
|
31
|
+
alias :camelized :app_const_base
|
32
|
+
|
33
|
+
def app_const
|
34
|
+
@app_const ||= "#{app_const_base}::Application"
|
35
|
+
end
|
36
|
+
|
37
|
+
def valid_const?
|
38
|
+
if /^\d/.match?(app_const)
|
39
|
+
raise Error, "Invalid application name #{original_app_name}. Please give a name which does not start with numbers."
|
40
|
+
elsif RESERVED_NAMES.include?(original_app_name)
|
41
|
+
raise Error, "Invalid application name #{original_app_name}. Please give a " \
|
42
|
+
"name which does not match one of the reserved rails " \
|
43
|
+
"words: #{RESERVED_NAMES.join(", ")}"
|
44
|
+
elsif Object.const_defined?(app_const_base)
|
45
|
+
raise Error, "Invalid application name #{original_app_name}, constant #{app_const_base} is already in use. Please choose another application name."
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Generators
|
5
|
+
module Database # :nodoc:
|
6
|
+
JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )
|
7
|
+
DATABASES = %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver ) + JDBC_DATABASES
|
8
|
+
|
9
|
+
def initialize(*)
|
10
|
+
super
|
11
|
+
convert_database_option_for_jruby
|
12
|
+
end
|
13
|
+
|
14
|
+
def gem_for_database(database = options[:database])
|
15
|
+
case database
|
16
|
+
when "mysql" then ["mysql2", [">= 0.4.4"]]
|
17
|
+
when "postgresql" then ["pg", [">= 0.18", "< 2.0"]]
|
18
|
+
when "oracle" then ["activerecord-oracle_enhanced-adapter", nil]
|
19
|
+
when "frontbase" then ["ruby-frontbase", nil]
|
20
|
+
when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
|
21
|
+
when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil]
|
22
|
+
when "jdbcsqlite3" then ["activerecord-jdbcsqlite3-adapter", nil]
|
23
|
+
when "jdbcpostgresql" then ["activerecord-jdbcpostgresql-adapter", nil]
|
24
|
+
when "jdbc" then ["activerecord-jdbc-adapter", nil]
|
25
|
+
else [database, nil]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def convert_database_option_for_jruby
|
30
|
+
if defined?(JRUBY_VERSION)
|
31
|
+
opt = options.dup
|
32
|
+
case opt[:database]
|
33
|
+
when "postgresql" then opt[:database] = "jdbcpostgresql"
|
34
|
+
when "mysql" then opt[:database] = "jdbcmysql"
|
35
|
+
when "sqlite3" then opt[:database] = "jdbcsqlite3"
|
36
|
+
end
|
37
|
+
self.options = opt.freeze
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def mysql_socket
|
43
|
+
@mysql_socket ||= [
|
44
|
+
"/tmp/mysql.sock", # default
|
45
|
+
"/var/run/mysqld/mysqld.sock", # debian/gentoo
|
46
|
+
"/var/tmp/mysql.sock", # freebsd
|
47
|
+
"/var/lib/mysql/mysql.sock", # fedora
|
48
|
+
"/opt/local/lib/mysql/mysql.sock", # fedora
|
49
|
+
"/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
|
50
|
+
"/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
|
51
|
+
"/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
|
52
|
+
"/opt/lampp/var/mysql/mysql.sock" # xampp for linux
|
53
|
+
].find { |f| File.exist?(f) } unless Gem.win_platform?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -16,7 +16,7 @@
|
|
16
16
|
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
|
17
17
|
<tr>
|
18
18
|
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
19
|
-
<td><%%= <%= singular_table_name %>.<%= attribute.
|
19
|
+
<td><%%= <%= singular_table_name %>.<%= attribute.column_name %> %></td>
|
20
20
|
<% end -%>
|
21
21
|
<td><%%= link_to 'Show', <%= model_resource_name %> %></td>
|
22
22
|
<td><%%= link_to 'Edit', edit_<%= singular_route_name %>_path(<%= singular_table_name %>) %></td>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
4
4
|
<p>
|
5
5
|
<strong><%= attribute.human_name %>:</strong>
|
6
|
-
<%%= @<%= singular_table_name %>.<%= attribute.
|
6
|
+
<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>
|
7
7
|
</p>
|
8
8
|
|
9
9
|
<% end -%>
|
@@ -39,23 +39,23 @@ module Rails
|
|
39
39
|
|
40
40
|
private
|
41
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
|
+
return type, options
|
55
|
+
else
|
56
|
+
return type, {}
|
57
|
+
end
|
57
58
|
end
|
58
|
-
end
|
59
59
|
end
|
60
60
|
|
61
61
|
def initialize(name, type = nil, index_type = false, attr_options = {})
|
@@ -153,7 +153,7 @@ module Rails
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def inject_options
|
156
|
-
"".
|
156
|
+
(+"").tap { |s| options_for_migration.each { |k, v| s << ", #{k}: #{v.inspect}" } }
|
157
157
|
end
|
158
158
|
|
159
159
|
def inject_index_options
|
@@ -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.
|
@@ -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
|
@@ -81,7 +80,6 @@ module Rails
|
|
81
80
|
directory "app"
|
82
81
|
|
83
82
|
keep_file "app/assets/images"
|
84
|
-
empty_directory_with_keep_file "app/assets/javascripts/channels" unless options[:skip_action_cable]
|
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
|
|
@@ -249,14 +242,13 @@ module Rails
|
|
249
242
|
# We need to store the RAILS_DEV_PATH in a constant, otherwise the path
|
250
243
|
# can change in Ruby 1.8.7 when we FileUtils.cd.
|
251
244
|
RAILS_DEV_PATH = File.expand_path("../../../../../..", __dir__)
|
252
|
-
RESERVED_NAMES = %w[application destroy plugin runner test]
|
253
245
|
|
254
246
|
class AppGenerator < AppBase # :nodoc:
|
255
247
|
WEBPACKS = %w( react vue angular elm stimulus )
|
256
248
|
|
257
249
|
add_shared_options_for "application"
|
258
250
|
|
259
|
-
# Add
|
251
|
+
# Add rails command options
|
260
252
|
class_option :version, type: :boolean, aliases: "-v", group: :rails,
|
261
253
|
desc: "Show Rails version number and quit"
|
262
254
|
|
@@ -266,21 +258,26 @@ module Rails
|
|
266
258
|
class_option :skip_bundle, type: :boolean, aliases: "-B", default: false,
|
267
259
|
desc: "Don't run bundle install"
|
268
260
|
|
269
|
-
class_option :webpack, type: :string, default: nil,
|
270
|
-
desc: "Preconfigure
|
261
|
+
class_option :webpack, type: :string, aliases: "--webpacker", default: nil,
|
262
|
+
desc: "Preconfigure Webpack with a particular framework (options: #{WEBPACKS.join(", ")})"
|
263
|
+
|
264
|
+
class_option :skip_webpack_install, type: :boolean, default: false,
|
265
|
+
desc: "Don't run Webpack install"
|
271
266
|
|
272
267
|
def initialize(*args)
|
273
268
|
super
|
274
269
|
|
275
270
|
if !options[:skip_active_record] && !DATABASES.include?(options[:database])
|
276
|
-
raise Error, "Invalid value for --database option. Supported
|
271
|
+
raise Error, "Invalid value for --database option. Supported preconfigurations are: #{DATABASES.join(", ")}."
|
277
272
|
end
|
278
273
|
|
279
274
|
# Force sprockets and yarn to be skipped when generating API only apps.
|
280
275
|
# Can't modify options hash as it's frozen by default.
|
281
276
|
if options[:api]
|
282
|
-
self.options = options.merge(skip_sprockets: true, skip_javascript: true
|
277
|
+
self.options = options.merge(skip_sprockets: true, skip_javascript: true).freeze
|
283
278
|
end
|
279
|
+
|
280
|
+
@after_bundle_callbacks = []
|
284
281
|
end
|
285
282
|
|
286
283
|
public_task :set_default_accessors!
|
@@ -294,7 +291,7 @@ module Rails
|
|
294
291
|
build(:gitignore) unless options[:skip_git]
|
295
292
|
build(:gemfile) unless options[:skip_gemfile]
|
296
293
|
build(:version_control)
|
297
|
-
build(:package_json) unless options[:
|
294
|
+
build(:package_json) unless options[:skip_javascript]
|
298
295
|
end
|
299
296
|
|
300
297
|
def create_app_files
|
@@ -310,6 +307,13 @@ module Rails
|
|
310
307
|
end
|
311
308
|
remove_task :update_bin_files
|
312
309
|
|
310
|
+
def update_active_storage
|
311
|
+
unless skip_active_storage?
|
312
|
+
rails_command "active_storage:update"
|
313
|
+
end
|
314
|
+
end
|
315
|
+
remove_task :update_active_storage
|
316
|
+
|
313
317
|
def create_config_files
|
314
318
|
build(:config)
|
315
319
|
end
|
@@ -328,7 +332,7 @@ module Rails
|
|
328
332
|
end
|
329
333
|
|
330
334
|
def display_upgrade_guide_info
|
331
|
-
say "\nAfter this, check Rails upgrade guide at
|
335
|
+
say "\nAfter this, check Rails upgrade guide at https://guides.rubyonrails.org/upgrading_ruby_on_rails.html for more details about upgrading your app."
|
332
336
|
end
|
333
337
|
remove_task :display_upgrade_guide_info
|
334
338
|
|
@@ -416,7 +420,7 @@ module Rails
|
|
416
420
|
|
417
421
|
def delete_js_folder_skipping_javascript
|
418
422
|
if options[:skip_javascript]
|
419
|
-
remove_dir "app/
|
423
|
+
remove_dir "app/javascript"
|
420
424
|
end
|
421
425
|
end
|
422
426
|
|
@@ -443,8 +447,9 @@ module Rails
|
|
443
447
|
|
444
448
|
def delete_action_cable_files_skipping_action_cable
|
445
449
|
if options[:skip_action_cable]
|
446
|
-
|
450
|
+
remove_dir "app/javascript/channels"
|
447
451
|
remove_dir "app/channels"
|
452
|
+
remove_dir "test/channels"
|
448
453
|
end
|
449
454
|
end
|
450
455
|
|
@@ -463,12 +468,12 @@ module Rails
|
|
463
468
|
|
464
469
|
def delete_new_framework_defaults
|
465
470
|
unless options[:update]
|
466
|
-
remove_file "config/initializers/
|
471
|
+
remove_file "config/initializers/new_framework_defaults_6_0.rb"
|
467
472
|
end
|
468
473
|
end
|
469
474
|
|
470
|
-
def
|
471
|
-
remove_file "bin/yarn" if options[:
|
475
|
+
def delete_bin_yarn
|
476
|
+
remove_file "bin/yarn" if options[:skip_javascript]
|
472
477
|
end
|
473
478
|
|
474
479
|
def finish_template
|
@@ -476,7 +481,8 @@ module Rails
|
|
476
481
|
end
|
477
482
|
|
478
483
|
public_task :apply_rails_template, :run_bundle
|
479
|
-
public_task :
|
484
|
+
public_task :generate_bundler_binstub, :generate_spring_binstubs
|
485
|
+
public_task :run_webpack
|
480
486
|
|
481
487
|
def run_after_bundle_callbacks
|
482
488
|
@after_bundle_callbacks.each(&:call)
|
@@ -493,54 +499,14 @@ module Rails
|
|
493
499
|
create_file(*args, &block)
|
494
500
|
end
|
495
501
|
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
def defined_app_const_base
|
505
|
-
Rails.respond_to?(:application) && defined?(Rails::Application) &&
|
506
|
-
Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "")
|
507
|
-
end
|
508
|
-
|
509
|
-
alias :defined_app_const_base? :defined_app_const_base
|
510
|
-
|
511
|
-
def app_const_base
|
512
|
-
@app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, "_").squeeze("_").camelize
|
513
|
-
end
|
514
|
-
alias :camelized :app_const_base
|
515
|
-
|
516
|
-
def app_const
|
517
|
-
@app_const ||= "#{app_const_base}::Application"
|
518
|
-
end
|
519
|
-
|
520
|
-
def valid_const?
|
521
|
-
if app_const =~ /^\d/
|
522
|
-
raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
|
523
|
-
elsif RESERVED_NAMES.include?(app_name)
|
524
|
-
raise Error, "Invalid application name #{app_name}. Please give a " \
|
525
|
-
"name which does not match one of the reserved rails " \
|
526
|
-
"words: #{RESERVED_NAMES.join(", ")}"
|
527
|
-
elsif Object.const_defined?(app_const_base)
|
528
|
-
raise Error, "Invalid application name #{app_name}, constant #{app_const_base} is already in use. Please choose another application name."
|
529
|
-
end
|
530
|
-
end
|
531
|
-
|
532
|
-
def mysql_socket
|
533
|
-
@mysql_socket ||= [
|
534
|
-
"/tmp/mysql.sock", # default
|
535
|
-
"/var/run/mysqld/mysqld.sock", # debian/gentoo
|
536
|
-
"/var/tmp/mysql.sock", # freebsd
|
537
|
-
"/var/lib/mysql/mysql.sock", # fedora
|
538
|
-
"/opt/local/lib/mysql/mysql.sock", # fedora
|
539
|
-
"/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
|
540
|
-
"/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
|
541
|
-
"/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
|
542
|
-
"/opt/lampp/var/mysql/mysql.sock" # xampp for linux
|
543
|
-
].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
|
544
510
|
end
|
545
511
|
|
546
512
|
def get_builder_class
|