railties 7.0.8.4 → 7.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +574 -218
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.md +99 -0
  5. data/README.rdoc +4 -4
  6. data/lib/minitest/rails_plugin.rb +63 -0
  7. data/lib/rails/api/task.rb +35 -4
  8. data/lib/rails/app_updater.rb +1 -1
  9. data/lib/rails/application/bootstrap.rb +12 -3
  10. data/lib/rails/application/configuration.rb +179 -67
  11. data/lib/rails/application/default_middleware_stack.rb +8 -2
  12. data/lib/rails/application/dummy_config.rb +19 -0
  13. data/lib/rails/application/finisher.rb +40 -33
  14. data/lib/rails/application.rb +112 -24
  15. data/lib/rails/backtrace_cleaner.rb +1 -1
  16. data/lib/rails/cli.rb +5 -2
  17. data/lib/rails/command/actions.rb +10 -12
  18. data/lib/rails/command/base.rb +55 -53
  19. data/lib/rails/command/environment_argument.rb +32 -16
  20. data/lib/rails/command/helpers/editor.rb +17 -12
  21. data/lib/rails/command.rb +84 -33
  22. data/lib/rails/commands/about/about_command.rb +14 -0
  23. data/lib/rails/commands/application/application_command.rb +2 -0
  24. data/lib/rails/commands/console/console_command.rb +14 -14
  25. data/lib/rails/commands/credentials/USAGE +53 -55
  26. data/lib/rails/commands/credentials/credentials_command/diffing.rb +5 -3
  27. data/lib/rails/commands/credentials/credentials_command.rb +64 -70
  28. data/lib/rails/commands/db/system/change/change_command.rb +2 -1
  29. data/lib/rails/commands/dbconsole/dbconsole_command.rb +25 -115
  30. data/lib/rails/commands/destroy/destroy_command.rb +3 -2
  31. data/lib/rails/commands/dev/dev_command.rb +1 -6
  32. data/lib/rails/commands/encrypted/USAGE +15 -20
  33. data/lib/rails/commands/encrypted/encrypted_command.rb +46 -35
  34. data/lib/rails/commands/gem_help/USAGE +16 -0
  35. data/lib/rails/commands/gem_help/gem_help_command.rb +13 -0
  36. data/lib/rails/commands/generate/generate_command.rb +2 -2
  37. data/lib/rails/commands/help/USAGE +13 -13
  38. data/lib/rails/commands/help/help_command.rb +21 -2
  39. data/lib/rails/commands/initializers/initializers_command.rb +1 -4
  40. data/lib/rails/commands/middleware/middleware_command.rb +17 -0
  41. data/lib/rails/commands/new/new_command.rb +2 -0
  42. data/lib/rails/commands/notes/notes_command.rb +2 -1
  43. data/lib/rails/commands/plugin/plugin_command.rb +2 -0
  44. data/lib/rails/commands/rake/rake_command.rb +25 -22
  45. data/lib/rails/commands/restart/restart_command.rb +14 -0
  46. data/lib/rails/commands/routes/routes_command.rb +13 -1
  47. data/lib/rails/commands/runner/USAGE +14 -12
  48. data/lib/rails/commands/runner/runner_command.rb +32 -20
  49. data/lib/rails/commands/secret/secret_command.rb +13 -0
  50. data/lib/rails/commands/secrets/USAGE +44 -49
  51. data/lib/rails/commands/secrets/secrets_command.rb +19 -38
  52. data/lib/rails/commands/server/server_command.rb +32 -31
  53. data/lib/rails/commands/test/USAGE +14 -0
  54. data/lib/rails/commands/test/test_command.rb +56 -14
  55. data/lib/rails/commands/unused_routes/unused_routes_command.rb +75 -0
  56. data/lib/rails/commands/version/version_command.rb +1 -0
  57. data/lib/rails/configuration.rb +5 -5
  58. data/lib/rails/console/app.rb +1 -4
  59. data/lib/rails/deprecator.rb +7 -0
  60. data/lib/rails/engine/configuration.rb +5 -0
  61. data/lib/rails/engine.rb +32 -11
  62. data/lib/rails/gem_version.rb +4 -4
  63. data/lib/rails/generators/actions.rb +6 -15
  64. data/lib/rails/generators/active_model.rb +2 -2
  65. data/lib/rails/generators/app_base.rb +354 -83
  66. data/lib/rails/generators/app_name.rb +3 -14
  67. data/lib/rails/generators/base.rb +12 -4
  68. data/lib/rails/generators/database.rb +19 -1
  69. data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +1 -1
  70. data/lib/rails/generators/generated_attribute.rb +2 -0
  71. data/lib/rails/generators/migration.rb +1 -2
  72. data/lib/rails/generators/model_helpers.rb +2 -1
  73. data/lib/rails/generators/rails/app/USAGE +15 -6
  74. data/lib/rails/generators/rails/app/app_generator.rb +84 -60
  75. data/lib/rails/generators/rails/app/templates/Dockerfile.tt +107 -0
  76. data/lib/rails/generators/rails/app/templates/Gemfile.tt +8 -10
  77. data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +1 -1
  78. data/lib/rails/generators/rails/app/templates/bin/setup.tt +10 -1
  79. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +4 -17
  80. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +3 -3
  81. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +0 -2
  82. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +3 -3
  83. data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +59 -0
  84. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +10 -2
  85. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +28 -24
  86. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +11 -7
  87. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +2 -0
  88. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +2 -2
  89. data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +1 -1
  90. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_1.rb.tt +223 -0
  91. data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -9
  92. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +11 -13
  93. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +10 -19
  94. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +4 -0
  95. data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +6 -4
  96. data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +10 -0
  97. data/lib/rails/generators/rails/app/templates/dockerignore.tt +43 -0
  98. data/lib/rails/generators/rails/app/templates/gitignore.tt +1 -9
  99. data/lib/rails/generators/rails/app/templates/node-version.tt +1 -0
  100. data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +10 -8
  101. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +9 -7
  102. data/lib/rails/generators/rails/application_record/application_record_generator.rb +4 -0
  103. data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +2 -1
  104. data/lib/rails/generators/rails/controller/USAGE +12 -4
  105. data/lib/rails/generators/rails/controller/controller_generator.rb +5 -0
  106. data/lib/rails/generators/rails/controller/templates/controller.rb.tt +1 -1
  107. data/lib/rails/generators/rails/credentials/credentials_generator.rb +29 -24
  108. data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +8 -0
  109. data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -2
  110. data/lib/rails/generators/rails/migration/USAGE +21 -11
  111. data/lib/rails/generators/rails/model/model_generator.rb +4 -0
  112. data/lib/rails/generators/rails/plugin/USAGE +17 -6
  113. data/lib/rails/generators/rails/plugin/plugin_generator.rb +5 -15
  114. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +2 -2
  115. data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +1 -1
  116. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -17
  117. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -2
  118. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +4 -4
  119. data/lib/rails/generators/rails/resource/resource_generator.rb +6 -0
  120. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -1
  121. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
  122. data/lib/rails/generators/test_case.rb +2 -2
  123. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +1 -1
  124. data/lib/rails/generators/testing/{behaviour.rb → behavior.rb} +4 -1
  125. data/lib/rails/generators.rb +5 -13
  126. data/lib/rails/health_controller.rb +55 -0
  127. data/lib/rails/info.rb +1 -1
  128. data/lib/rails/info_controller.rb +31 -11
  129. data/lib/rails/mailers_controller.rb +15 -5
  130. data/lib/rails/paths.rb +13 -10
  131. data/lib/rails/rack/logger.rb +15 -12
  132. data/lib/rails/rackup/server.rb +15 -0
  133. data/lib/rails/railtie/configuration.rb +14 -1
  134. data/lib/rails/railtie.rb +18 -18
  135. data/lib/rails/ruby_version_check.rb +2 -0
  136. data/lib/rails/source_annotation_extractor.rb +67 -18
  137. data/lib/rails/tasks/engine.rake +8 -8
  138. data/lib/rails/tasks/framework.rake +4 -10
  139. data/lib/rails/tasks/log.rake +1 -1
  140. data/lib/rails/tasks/misc.rake +3 -14
  141. data/lib/rails/tasks/statistics.rake +5 -4
  142. data/lib/rails/tasks/tmp.rake +5 -5
  143. data/lib/rails/tasks/zeitwerk.rake +1 -1
  144. data/lib/rails/tasks.rb +0 -2
  145. data/lib/rails/templates/rails/mailers/email.html.erb +25 -0
  146. data/lib/rails/templates/rails/mailers/index.html.erb +14 -7
  147. data/lib/rails/templates/rails/mailers/mailer.html.erb +11 -5
  148. data/lib/rails/templates/rails/welcome/index.html.erb +1 -0
  149. data/lib/rails/test_help.rb +7 -7
  150. data/lib/rails/test_unit/line_filtering.rb +1 -1
  151. data/lib/rails/test_unit/reporter.rb +6 -2
  152. data/lib/rails/test_unit/runner.rb +36 -18
  153. data/lib/rails/test_unit/test_parser.rb +88 -0
  154. data/lib/rails/test_unit/testing.rake +13 -33
  155. data/lib/rails/version.rb +1 -1
  156. data/lib/rails.rb +15 -15
  157. metadata +66 -31
  158. data/RDOC_MAIN.rdoc +0 -97
  159. data/lib/rails/application/dummy_erb_compiler.rb +0 -18
  160. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +0 -143
  161. data/lib/rails/generators/rails/model/USAGE +0 -113
  162. data/lib/rails/tasks/middleware.rake +0 -9
  163. data/lib/rails/tasks/restart.rake +0 -9
@@ -1,43 +1,34 @@
1
+ # This configuration file will be evaluated by Puma. The top-level methods that
2
+ # are invoked here are part of Puma's configuration DSL. For more information
3
+ # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
4
+
1
5
  # Puma can serve each request in a thread from an internal thread pool.
2
6
  # The `threads` method setting takes two numbers: a minimum and maximum.
3
7
  # Any libraries that use thread pools should be configured to match
4
8
  # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
9
  # and maximum; this matches the default thread size of Active Record.
6
- #
7
10
  max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8
11
  min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
9
12
  threads min_threads_count, max_threads_count
10
13
 
14
+ # Specifies that the worker count should equal the number of processors in production.
15
+ if ENV["RAILS_ENV"] == "production"
16
+ worker_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.physical_processor_count })
17
+ workers worker_count if worker_count > 1
18
+ end
19
+
11
20
  # Specifies the `worker_timeout` threshold that Puma will use to wait before
12
21
  # terminating a worker in development environments.
13
- #
14
22
  worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
15
23
 
16
24
  # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
17
- #
18
25
  port ENV.fetch("PORT") { 3000 }
19
26
 
20
27
  # Specifies the `environment` that Puma will run in.
21
- #
22
28
  environment ENV.fetch("RAILS_ENV") { "development" }
23
29
 
24
30
  # Specifies the `pidfile` that Puma will use.
25
31
  pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
26
32
 
27
- # Specifies the number of `workers` to boot in clustered mode.
28
- # Workers are forked web server processes. If using threads and workers together
29
- # the concurrency of the application would be max `threads` * `workers`.
30
- # Workers do not work on JRuby or Windows (both of which do not support
31
- # processes).
32
- #
33
- # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
34
-
35
- # Use the `preload_app!` method when specifying a `workers` number.
36
- # This directive tells Puma to first boot the application and load code
37
- # before forking the application. This takes advantage of Copy On Write
38
- # process behavior so workers use less memory.
39
- #
40
- # preload_app!
41
-
42
33
  # Allow puma to be restarted by `bin/rails restart` command.
43
34
  plugin :tmp_restart
@@ -1,6 +1,10 @@
1
1
  Rails.application.routes.draw do
2
2
  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
3
3
 
4
+ # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
5
+ # Can be used by load balancers and uptime monitors to verify that the app is live.
6
+ get "up" => "rails/health#show", as: :rails_health_check
7
+
4
8
  # Defines the root path route ("/")
5
9
  # root "articles#index"
6
10
  end
@@ -1,7 +1,9 @@
1
- # This file should contain all the record creation needed to seed the database with its default values.
1
+ # This file should ensure the existence of records required to run the application in every environment (production,
2
+ # development, test). The code here should be idempotent so that it can be executed at any point in every environment.
2
3
  # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
3
4
  #
4
- # Examples:
5
+ # Example:
5
6
  #
6
- # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
7
- # Character.create(name: "Luke", movie: movies.first)
7
+ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
8
+ # MovieGenre.find_or_create_by!(name: genre_name)
9
+ # end
@@ -0,0 +1,10 @@
1
+ #!/bin/bash -e
2
+
3
+ <% unless skip_active_record? -%>
4
+ # If running the rails server then create or migrate existing database
5
+ if [ "${*}" == "./bin/rails server" ]; then
6
+ ./bin/rails db:prepare
7
+ fi
8
+
9
+ <% end -%>
10
+ exec "${@}"
@@ -0,0 +1,43 @@
1
+ # See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
2
+
3
+ # Ignore git directory.
4
+ /.git/
5
+
6
+ # Ignore bundler config.
7
+ /.bundle
8
+
9
+ # Ignore all default key files.
10
+ /config/master.key
11
+ /config/credentials/*.key
12
+
13
+ # Ignore all environment files.
14
+ /.env*
15
+ !/.env.example
16
+
17
+ # Ignore all logfiles and tempfiles.
18
+ /log/*
19
+ /tmp/*
20
+ <% if keeps? -%>
21
+ !/log/.keep
22
+ !/tmp/.keep
23
+
24
+ # Ignore pidfiles, but keep the directory.
25
+ /tmp/pids/*
26
+ !/tmp/pids/.keep
27
+ <% end -%>
28
+
29
+ # Ignore storage (uploaded files in development and any SQLite databases).
30
+ /storage/*
31
+ <% if keeps? -%>
32
+ !/storage/.keep
33
+ /tmp/storage/*
34
+ !/tmp/storage/.keep
35
+ <% end -%>
36
+ <% unless options.api? -%>
37
+
38
+ # Ignore assets.
39
+ /node_modules/
40
+ /app/assets/builds/*
41
+ !/app/assets/builds/.keep
42
+ /public/assets
43
+ <% end -%>
@@ -7,12 +7,6 @@
7
7
  # Ignore bundler config.
8
8
  /.bundle
9
9
 
10
- <% if sqlite3? -%>
11
- # Ignore the default SQLite database.
12
- /db/*.sqlite3
13
- /db/*.sqlite3-*
14
-
15
- <% end -%>
16
10
  # Ignore all logfiles and tempfiles.
17
11
  /log/*
18
12
  /tmp/*
@@ -26,8 +20,7 @@
26
20
  !/tmp/pids/.keep
27
21
  <% end -%>
28
22
 
29
- <% unless skip_active_storage? -%>
30
- # Ignore uploaded files in development.
23
+ # Ignore storage (uploaded files in development and any SQLite databases).
31
24
  /storage/*
32
25
  <% if keeps? -%>
33
26
  !/storage/.keep
@@ -35,7 +28,6 @@
35
28
  !/tmp/storage/
36
29
  !/tmp/storage/.keep
37
30
  <% end -%>
38
- <% end -%>
39
31
  <% unless options.api? -%>
40
32
 
41
33
  /public/assets
@@ -0,0 +1 @@
1
+ <%= node_version %>
@@ -1,11 +1,13 @@
1
1
  require "test_helper"
2
2
 
3
- class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
4
- # test "connects with cookies" do
5
- # cookies.signed[:user_id] = 42
6
- #
7
- # connect
8
- #
9
- # assert_equal connection.user_id, "42"
10
- # end
3
+ module ApplicationCable
4
+ class ConnectionTest < ActionCable::Connection::TestCase
5
+ # test "connects with cookies" do
6
+ # cookies.signed[:user_id] = 42
7
+ #
8
+ # connect
9
+ #
10
+ # assert_equal connection.user_id, "42"
11
+ # end
12
+ end
11
13
  end
@@ -2,18 +2,20 @@ ENV["RAILS_ENV"] ||= "test"
2
2
  require_relative "../config/environment"
3
3
  require "rails/test_help"
4
4
 
5
- class ActiveSupport::TestCase
6
- # Run tests in parallel with specified workers
5
+ module ActiveSupport
6
+ class TestCase
7
+ # Run tests in parallel with specified workers
7
8
  <% if Process.respond_to?(:fork) && !Gem.win_platform? -%>
8
- parallelize(workers: :number_of_processors)
9
+ parallelize(workers: :number_of_processors)
9
10
  <%- else -%>
10
- parallelize(workers: :number_of_processors, with: :threads)
11
+ parallelize(workers: :number_of_processors, with: :threads)
11
12
  <% end -%>
12
13
 
13
14
  <% unless options[:skip_active_record] -%>
14
- # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
15
- fixtures :all
15
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
16
+ fixtures :all
16
17
 
17
18
  <% end -%>
18
- # Add more helper methods to be used by all tests here...
19
+ # Add more helper methods to be used by all tests here...
20
+ end
19
21
  end
@@ -4,6 +4,10 @@ module Rails
4
4
  module Generators
5
5
  class ApplicationRecordGenerator < Base # :nodoc:
6
6
  hook_for :orm, required: true, desc: "ORM to be invoked"
7
+
8
+ class << self
9
+ delegate(:desc, to: :orm_generator)
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -6,6 +6,7 @@ module Rails
6
6
  module Generators
7
7
  class BenchmarkGenerator < NamedBase
8
8
  IPS_GEM_NAME = "benchmark-ips"
9
+ IPS_GEM_USED_REGEXP = /gem.*\b#{IPS_GEM_NAME}\b.*/
9
10
 
10
11
  argument :reports, type: :array, default: ["before", "after"]
11
12
 
@@ -21,7 +22,7 @@ module Rails
21
22
 
22
23
  def ips_installed?
23
24
  in_root do
24
- return File.read("Gemfile").match?(/gem.*\b#{IPS_GEM_NAME}\b.*/)
25
+ return File.read("Gemfile").match?(IPS_GEM_USED_REGEXP)
25
26
  end
26
27
  end
27
28
  end
@@ -1,6 +1,6 @@
1
1
  Description:
2
2
  Generates a new controller and its views. Pass the controller name, either
3
- CamelCased or under_scored, and a list of views as arguments.
3
+ CamelCased or under_scored, and a list of actions as arguments.
4
4
 
5
5
  To create a controller within a module, specify the controller name as a
6
6
  path like 'parent_module/controller_name'.
@@ -8,11 +8,19 @@ Description:
8
8
  This generates a controller class in app/controllers and invokes helper,
9
9
  template engine, assets, and test framework generators.
10
10
 
11
- Example:
12
- `bin/rails generate controller CreditCards open debit credit close`
11
+ Examples:
12
+ `bin/rails generate controller credit_cards open debit credit close`
13
13
 
14
- CreditCards controller with URLs like /credit_cards/debit.
14
+ This generates a `CreditCardsController` with routes like /credit_cards/debit.
15
15
  Controller: app/controllers/credit_cards_controller.rb
16
16
  Test: test/controllers/credit_cards_controller_test.rb
17
17
  Views: app/views/credit_cards/debit.html.erb [...]
18
18
  Helper: app/helpers/credit_cards_helper.rb
19
+
20
+ `bin/rails generate controller users index --skip-routes`
21
+
22
+ This generates a `UsersController` with an index action and no routes.
23
+
24
+ `bin/rails generate controller admin/dashboard --parent=admin_controller`
25
+
26
+ This generates a `Admin::DashboardController` with an `AdminController` parent class.
@@ -6,6 +6,7 @@ module Rails
6
6
  argument :actions, type: :array, default: [], banner: "action action"
7
7
  class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
8
8
  class_option :helper, type: :boolean
9
+ class_option :parent, type: :string, default: "ApplicationController", desc: "The parent class for the generated controller"
9
10
 
10
11
  check_class_collision suffix: "Controller"
11
12
 
@@ -25,6 +26,10 @@ module Rails
25
26
  end
26
27
 
27
28
  private
29
+ def parent_class_name
30
+ options[:parent]
31
+ end
32
+
28
33
  def file_name
29
34
  @_file_name ||= remove_possible_suffix(super)
30
35
  end
@@ -1,5 +1,5 @@
1
1
  <% module_namespacing do -%>
2
- class <%= class_name %>Controller < ApplicationController
2
+ class <%= class_name %>Controller < <%= parent_class_name.classify %>
3
3
  <% actions.each do |action| -%>
4
4
  def <%= action %>
5
5
  end
@@ -7,49 +7,54 @@ require "active_support/encrypted_configuration"
7
7
  module Rails
8
8
  module Generators
9
9
  class CredentialsGenerator < Base # :nodoc:
10
+ argument :content_path, default: "config/credentials.yml.enc"
11
+ argument :key_path, default: "config/master.key"
12
+ class_option :skip_secret_key_base, type: :boolean
13
+
10
14
  def add_credentials_file
11
- unless credentials.content_path.exist?
12
- template = credentials_template
15
+ in_root do
16
+ return if File.exist?(content_path)
13
17
 
14
- say "Adding #{credentials.content_path} to store encrypted credentials."
18
+ say "Adding #{content_path} to store encrypted credentials."
15
19
  say ""
20
+
21
+ content = render_template_to_encrypted_file
22
+
16
23
  say "The following content has been encrypted with the Rails master key:"
17
24
  say ""
18
- say template, :on_green
25
+ say content, :on_green
19
26
  say ""
20
-
21
- add_credentials_file_silently(template)
22
-
23
27
  say "You can edit encrypted credentials with `bin/rails credentials:edit`."
24
28
  say ""
25
29
  end
26
30
  end
27
31
 
28
- def add_credentials_file_silently(template = nil)
29
- unless credentials.content_path.exist?
30
- credentials.write(credentials_template)
31
- end
32
- end
33
-
34
32
  private
35
- def credentials
33
+ def encrypted_file
36
34
  ActiveSupport::EncryptedConfiguration.new(
37
- config_path: "config/credentials.yml.enc",
38
- key_path: "config/master.key",
35
+ config_path: content_path,
36
+ key_path: key_path,
39
37
  env_key: "RAILS_MASTER_KEY",
40
38
  raise_if_missing_key: true
41
39
  )
42
40
  end
43
41
 
44
- def credentials_template
45
- <<~YAML
46
- # aws:
47
- # access_key_id: 123
48
- # secret_access_key: 345
42
+ def secret_key_base
43
+ @secret_key_base ||= SecureRandom.hex(64)
44
+ end
45
+
46
+ def render_template_to_encrypted_file
47
+ empty_directory File.dirname(content_path)
48
+
49
+ content = nil
50
+
51
+ encrypted_file.change do |tmp_path|
52
+ template("credentials.yml", tmp_path, force: true, verbose: false) do |rendered|
53
+ content = rendered
54
+ end
55
+ end
49
56
 
50
- # Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
51
- secret_key_base: #{SecureRandom.hex(64)}
52
- YAML
57
+ content
53
58
  end
54
59
  end
55
60
  end
@@ -0,0 +1,8 @@
1
+ # aws:
2
+ # access_key_id: 123
3
+ # secret_access_key: 345
4
+ <% unless options.skip_secret_key_base? -%>
5
+
6
+ # Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
7
+ secret_key_base: <%= secret_key_base %>
8
+ <% end -%>
@@ -26,8 +26,7 @@ module Rails
26
26
  end
27
27
 
28
28
  def add_key_file_silently(key_path, key = nil)
29
- create_file key_path, key || ActiveSupport::EncryptedFile.generate_key
30
- key_path.chmod 0600
29
+ create_file key_path, key || ActiveSupport::EncryptedFile.generate_key, perm: 0600
31
30
  end
32
31
 
33
32
  def ignore_key_file(key_path, ignore: key_ignore(key_path))
@@ -5,31 +5,41 @@ Description:
5
5
  A migration class is generated in db/migrate prefixed by a timestamp of the current date and time.
6
6
 
7
7
  You can name your migration in either of these formats to generate add/remove
8
- column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
8
+ column lines from supplied attributes: add_{columns}_to_{table} or remove_{columns}_from_{table}.
9
9
 
10
- Example:
11
- `bin/rails generate migration AddSslFlag`
10
+ A migration name containing JoinTable will generate join tables for use with
11
+ has_and_belongs_to_many associations.
12
+
13
+ You can also name your migration create_{table} along with any attributes to generate a regular table.
14
+
15
+ Examples:
16
+ `bin/rails generate migration add_ssl_flag`
12
17
 
13
18
  If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
14
19
  db/migrate/20080514090912_add_ssl_flag.rb
15
20
 
16
- `bin/rails generate migration AddTitleBodyToPost title:string body:text published:boolean`
21
+ `bin/rails generate migration add_title_body_published_to_post title:string body:text published:boolean`
17
22
 
18
- This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with this in the Change migration:
23
+ This will create db/migrate/20080514090912_add_title_body_published_to_post.rb with this in the migration:
19
24
 
20
25
  add_column :posts, :title, :string
21
26
  add_column :posts, :body, :text
22
27
  add_column :posts, :published, :boolean
23
28
 
24
- Migration names containing JoinTable will generate join tables for use with
25
- has_and_belongs_to_many associations.
29
+ `bin/rails generate migration create_media_join_table artists musics:uniq`
26
30
 
27
- Example:
28
- `bin/rails g migration CreateMediaJoinTable artists musics:uniq`
29
-
30
- will create the migration
31
+ This will create a join table migration:
31
32
 
32
33
  create_join_table :artists, :musics do |t|
33
34
  # t.index [:artist_id, :music_id]
34
35
  t.index [:music_id, :artist_id], unique: true
35
36
  end
37
+
38
+ `bin/rails generate migration create_users email:string`
39
+
40
+ This will create the migration:
41
+
42
+ create_table :users do |t|
43
+ t.string :email
44
+ t.timestamps
45
+ end
@@ -9,6 +9,10 @@ module Rails
9
9
 
10
10
  argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
11
11
  hook_for :orm, required: true, desc: "ORM to be invoked"
12
+
13
+ class << self
14
+ delegate(:desc, to: :orm_generator)
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -1,10 +1,21 @@
1
1
  Description:
2
- The 'rails plugin new' command creates a skeleton for developing any
3
- kind of Rails extension with ability to run tests using dummy Rails
4
- application.
2
+ The `rails plugin new` command creates a Rails plugin with the ability
3
+ to run tests using a dummy Rails application. A plugin is a gem with
4
+ either a railtie or an engine.
5
5
 
6
- Example:
7
- rails plugin new ~/Code/Ruby/blog
6
+ Examples:
7
+ `rails plugin new ~/Code/Ruby/blog`
8
8
 
9
- This generates a skeletal Rails plugin in ~/Code/Ruby/blog.
9
+ This generates a Rails railtie gem in ~/Code/Ruby/blog.
10
10
  See the README in the newly created plugin to get going.
11
+
12
+ `rails plugin new blog --full`
13
+
14
+ This generates a full Rails engine gem in ./blog. The `--mountable`
15
+ option may also be used to generate a mountable, namespace-isolated
16
+ engine with assets and layouts.
17
+
18
+ `rails plugin new blog --mountable --skip-asset-pipeline`
19
+
20
+ This generates a mountable Rails engine gem at ./blog without an asset
21
+ pipeline. Any part of Rails can be skipped during plugin generation.
@@ -28,14 +28,14 @@ module Rails
28
28
 
29
29
  empty_directory_with_keep_file "app/models/concerns"
30
30
  empty_directory_with_keep_file "app/controllers/concerns"
31
- remove_dir "app/mailers" if skip_action_mailer?
31
+ remove_dir "app/mailers" if options[:skip_action_mailer]
32
32
  remove_dir "app/jobs" if options[:skip_active_job]
33
33
  elsif full?
34
34
  empty_directory_with_keep_file "app/models"
35
35
  empty_directory_with_keep_file "app/controllers"
36
36
  empty_directory_with_keep_file "app/models/concerns"
37
37
  empty_directory_with_keep_file "app/controllers/concerns"
38
- empty_directory_with_keep_file "app/mailers" unless skip_action_mailer?
38
+ empty_directory_with_keep_file "app/mailers" unless options[:skip_action_mailer]
39
39
  empty_directory_with_keep_file "app/jobs" unless options[:skip_active_job]
40
40
 
41
41
  unless api?
@@ -68,10 +68,7 @@ module Rails
68
68
 
69
69
  def version_control
70
70
  if !options[:skip_git] && !options[:pretend]
71
- run "git init", capture: options[:quiet], abort_on_failure: false
72
- if user_default_branch.strip.empty?
73
- `git symbolic-ref HEAD refs/heads/main`
74
- end
71
+ run git_init_command, capture: options[:quiet], abort_on_failure: false
75
72
  end
76
73
  end
77
74
 
@@ -127,10 +124,6 @@ module Rails
127
124
  def test_dummy_config
128
125
  template "rails/boot.rb", "#{dummy_path}/config/boot.rb", force: true
129
126
 
130
- insert_into_file "#{dummy_path}/config/application.rb", <<~RUBY, after: /^Bundler\.require.+\n/
131
- require #{namespaced_name.inspect}
132
- RUBY
133
-
134
127
  if mountable?
135
128
  template "rails/routes.rb", "#{dummy_path}/config/routes.rb", force: true
136
129
  end
@@ -191,11 +184,6 @@ module Rails
191
184
  append_file gemfile_in_app_path, entry
192
185
  end
193
186
  end
194
-
195
- private
196
- def user_default_branch
197
- @user_default_branch ||= `git config init.defaultbranch`
198
- end
199
187
  end
200
188
 
201
189
  module Generators
@@ -226,12 +214,14 @@ module Rails
226
214
  def initialize(*args)
227
215
  @dummy_path = nil
228
216
  super
217
+ imply_options
229
218
 
230
219
  if !engine? || !with_dummy_app?
231
220
  self.options = options.merge(skip_asset_pipeline: true).freeze
232
221
  end
233
222
  end
234
223
 
224
+ public_task :report_implied_options
235
225
  public_task :set_default_accessors!
236
226
  public_task :create_root
237
227
 
@@ -13,7 +13,7 @@ gemspec
13
13
  # Start debugger with binding.b [https://github.com/ruby/debug]
14
14
  # gem "debug", ">= 1.0.0"
15
15
  <% end -%>
16
- <% if RUBY_PLATFORM.match?(/bccwin|cygwin|emx|mingw|mswin|wince|java/) -%>
16
+ <% if RUBY_PLATFORM.match?(/mingw|mswin|java/) -%>
17
17
 
18
- gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
18
+ gem "tzinfo-data", platforms: %i[ <%= bundler_windows_platforms %> jruby ]
19
19
  <% end -%>
@@ -1,4 +1,4 @@
1
- Copyright <%= Date.today.year %> <%= author %>
1
+ Copyright <%= author %>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -11,21 +11,5 @@ APP_PATH = File.expand_path("../<%= dummy_path -%>/config/application", __dir__)
11
11
  ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
12
  require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
13
13
 
14
- <% if include_all_railties? -%>
15
- require "rails/all"
16
- <% else -%>
17
- require "rails"
18
- # Pick the frameworks you want:
19
- require "active_model/railtie"
20
- <%= comment_if :skip_active_job %>require "active_job/railtie"
21
- <%= comment_if :skip_active_record %>require "active_record/railtie"
22
- <%= comment_if :skip_active_storage %>require "active_storage/engine"
23
- require "action_controller/railtie"
24
- <%= comment_if :skip_action_mailer %>require "action_mailer/railtie"
25
- <%= comment_if :skip_action_mailbox %>require "action_mailbox/engine"
26
- <%= comment_if :skip_action_text %>require "action_text/engine"
27
- require "action_view/railtie"
28
- <%= comment_if :skip_action_cable %>require "action_cable/engine"
29
- <%= comment_if :skip_test %>require "rails/test_unit/railtie"
30
- <% end -%>
14
+ <%= rails_require_statement %>
31
15
  require "rails/engine/commands"
@@ -9,8 +9,6 @@
9
9
  /<%= dummy_path %>/db/*.sqlite3-*
10
10
  <% end -%>
11
11
  /<%= dummy_path %>/log/*.log
12
- <% unless skip_active_storage? -%>
13
12
  /<%= dummy_path %>/storage/
14
- <% end -%>
15
13
  /<%= dummy_path %>/tmp/
16
14
  <% end -%>
@@ -12,10 +12,10 @@ require "rails/test_help"
12
12
 
13
13
  <% unless options[:skip_active_record] -%>
14
14
  # Load fixtures from the engine
15
- if ActiveSupport::TestCase.respond_to?(:fixture_path=)
16
- ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
17
- ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
18
- ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
15
+ if ActiveSupport::TestCase.respond_to?(:fixture_paths=)
16
+ ActiveSupport::TestCase.fixture_paths = [File.expand_path("fixtures", __dir__)]
17
+ ActionDispatch::IntegrationTest.fixture_paths = ActiveSupport::TestCase.fixture_paths
18
+ ActiveSupport::TestCase.file_fixture_path = File.expand_path("fixtures", __dir__) + "/files"
19
19
  ActiveSupport::TestCase.fixtures :all
20
20
  end
21
21
  <% end -%>
@@ -16,6 +16,12 @@ module Rails
16
16
  desc: "Actions for the resource controller"
17
17
 
18
18
  hook_for :resource_route, required: true
19
+
20
+ class << self
21
+ def desc(description = nil)
22
+ ERB.new(File.read(usage_path)).result(binding)
23
+ end
24
+ end
19
25
  end
20
26
  end
21
27
  end