railties 5.1.7 → 5.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +77 -241
  3. data/RDOC_MAIN.rdoc +61 -43
  4. data/README.rdoc +1 -2
  5. data/exe/rails +3 -2
  6. data/lib/minitest/rails_plugin.rb +9 -13
  7. data/lib/rails.rb +4 -2
  8. data/lib/rails/all.rb +3 -0
  9. data/lib/rails/api/generator.rb +10 -1
  10. data/lib/rails/api/task.rb +11 -1
  11. data/lib/rails/app_loader.rb +18 -5
  12. data/lib/rails/app_updater.rb +34 -0
  13. data/lib/rails/application.rb +90 -18
  14. data/lib/rails/application/bootstrap.rb +2 -0
  15. data/lib/rails/application/configuration.rb +79 -36
  16. data/lib/rails/application/default_middleware_stack.rb +7 -1
  17. data/lib/rails/application/finisher.rb +3 -1
  18. data/lib/rails/application/routes_reloader.rb +21 -3
  19. data/lib/rails/application_controller.rb +3 -1
  20. data/lib/rails/backtrace_cleaner.rb +3 -1
  21. data/lib/rails/cli.rb +2 -0
  22. data/lib/rails/code_statistics.rb +2 -0
  23. data/lib/rails/code_statistics_calculator.rb +2 -0
  24. data/lib/rails/command.rb +3 -1
  25. data/lib/rails/command/actions.rb +6 -4
  26. data/lib/rails/command/base.rb +5 -3
  27. data/lib/rails/command/behavior.rb +2 -0
  28. data/lib/rails/command/environment_argument.rb +14 -1
  29. data/lib/rails/command/helpers/editor.rb +35 -0
  30. data/lib/rails/commands.rb +2 -0
  31. data/lib/rails/commands/application/application_command.rb +2 -0
  32. data/lib/rails/commands/console/console_command.rb +2 -3
  33. data/lib/rails/commands/credentials/USAGE +40 -0
  34. data/lib/rails/commands/credentials/credentials_command.rb +72 -0
  35. data/lib/rails/commands/dbconsole/dbconsole_command.rb +18 -7
  36. data/lib/rails/commands/destroy/destroy_command.rb +2 -0
  37. data/lib/rails/commands/encrypted/encrypted_command.rb +77 -0
  38. data/lib/rails/commands/generate/generate_command.rb +2 -0
  39. data/lib/rails/commands/help/help_command.rb +2 -0
  40. data/lib/rails/commands/new/new_command.rb +2 -0
  41. data/lib/rails/commands/plugin/plugin_command.rb +2 -0
  42. data/lib/rails/commands/rake/rake_command.rb +2 -0
  43. data/lib/rails/commands/runner/USAGE +3 -0
  44. data/lib/rails/commands/runner/runner_command.rb +7 -3
  45. data/lib/rails/commands/secrets/secrets_command.rb +15 -10
  46. data/lib/rails/commands/server/server_command.rb +24 -3
  47. data/lib/rails/commands/test/test_command.rb +18 -23
  48. data/lib/rails/commands/version/version_command.rb +2 -0
  49. data/lib/rails/configuration.rb +2 -0
  50. data/lib/rails/console/app.rb +2 -0
  51. data/lib/rails/console/helpers.rb +2 -0
  52. data/lib/rails/dev_caching.rb +2 -1
  53. data/lib/rails/engine.rb +3 -1
  54. data/lib/rails/engine/commands.rb +2 -0
  55. data/lib/rails/engine/configuration.rb +2 -0
  56. data/lib/rails/engine/railties.rb +2 -0
  57. data/lib/rails/engine/updater.rb +3 -1
  58. data/lib/rails/gem_version.rb +5 -3
  59. data/lib/rails/generators.rb +8 -3
  60. data/lib/rails/generators/actions.rb +53 -24
  61. data/lib/rails/generators/actions/create_migration.rb +2 -0
  62. data/lib/rails/generators/active_model.rb +2 -0
  63. data/lib/rails/generators/app_base.rb +94 -57
  64. data/lib/rails/generators/base.rb +40 -1
  65. data/lib/rails/generators/css/assets/assets_generator.rb +3 -1
  66. data/lib/rails/generators/css/scaffold/scaffold_generator.rb +5 -3
  67. data/lib/rails/generators/erb.rb +2 -0
  68. data/lib/rails/generators/erb/controller/controller_generator.rb +2 -0
  69. data/lib/rails/generators/erb/controller/templates/{view.html.erb → view.html.erb.tt} +0 -0
  70. data/lib/rails/generators/erb/mailer/mailer_generator.rb +2 -0
  71. data/lib/rails/generators/erb/mailer/templates/{view.html.erb → view.html.erb.tt} +0 -0
  72. data/lib/rails/generators/erb/mailer/templates/{view.text.erb → view.text.erb.tt} +0 -0
  73. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
  74. data/lib/rails/generators/erb/scaffold/templates/{_form.html.erb → _form.html.erb.tt} +4 -4
  75. data/lib/rails/generators/erb/scaffold/templates/{edit.html.erb → edit.html.erb.tt} +0 -0
  76. data/lib/rails/generators/erb/scaffold/templates/{index.html.erb → index.html.erb.tt} +4 -4
  77. data/lib/rails/generators/erb/scaffold/templates/{new.html.erb → new.html.erb.tt} +0 -0
  78. data/lib/rails/generators/erb/scaffold/templates/{show.html.erb → show.html.erb.tt} +0 -0
  79. data/lib/rails/generators/generated_attribute.rb +3 -1
  80. data/lib/rails/generators/js/assets/assets_generator.rb +3 -1
  81. data/lib/rails/generators/migration.rb +2 -0
  82. data/lib/rails/generators/model_helpers.rb +2 -0
  83. data/lib/rails/generators/named_base.rb +35 -45
  84. data/lib/rails/generators/rails/app/app_generator.rb +64 -23
  85. data/lib/rails/generators/rails/app/templates/{Gemfile → Gemfile.tt} +17 -6
  86. data/lib/rails/generators/rails/app/templates/{README.md → README.md.tt} +0 -0
  87. data/lib/rails/generators/rails/app/templates/{Rakefile → Rakefile.tt} +0 -0
  88. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +3 -0
  89. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/{cable.js → cable.js.tt} +0 -0
  90. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/{application.css → application.css.tt} +0 -0
  91. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/{channel.rb → channel.rb.tt} +0 -0
  92. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/{connection.rb → connection.rb.tt} +0 -0
  93. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +1 -4
  94. data/lib/rails/generators/rails/app/templates/app/helpers/{application_helper.rb → application_helper.rb.tt} +0 -0
  95. data/lib/rails/generators/rails/app/templates/app/jobs/{application_job.rb → application_job.rb.tt} +0 -0
  96. data/lib/rails/generators/rails/app/templates/app/mailers/{application_mailer.rb → application_mailer.rb.tt} +0 -0
  97. data/lib/rails/generators/rails/app/templates/app/models/{application_record.rb → application_record.rb.tt} +0 -0
  98. data/lib/rails/generators/rails/app/templates/bin/bundle.tt +2 -0
  99. data/lib/rails/generators/rails/app/templates/bin/{rails → rails.tt} +0 -0
  100. data/lib/rails/generators/rails/app/templates/bin/{rake → rake.tt} +0 -0
  101. data/lib/rails/generators/rails/app/templates/bin/setup.tt +5 -5
  102. data/lib/rails/generators/rails/app/templates/bin/update.tt +7 -3
  103. data/lib/rails/generators/rails/app/templates/bin/{yarn → yarn.tt} +3 -3
  104. data/lib/rails/generators/rails/app/templates/{config.ru → config.ru.tt} +0 -0
  105. data/lib/rails/generators/rails/app/templates/config/{application.rb → application.rb.tt} +2 -1
  106. data/lib/rails/generators/rails/app/templates/config/{boot.rb → boot.rb.tt} +1 -0
  107. data/lib/rails/generators/rails/app/templates/config/{cable.yml → cable.yml.tt} +1 -1
  108. data/lib/rails/generators/rails/app/templates/config/databases/{frontbase.yml → frontbase.yml.tt} +0 -0
  109. data/lib/rails/generators/rails/app/templates/config/databases/{ibm_db.yml → ibm_db.yml.tt} +0 -0
  110. data/lib/rails/generators/rails/app/templates/config/databases/{jdbc.yml → jdbc.yml.tt} +0 -0
  111. data/lib/rails/generators/rails/app/templates/config/databases/{jdbcmysql.yml → jdbcmysql.yml.tt} +1 -1
  112. data/lib/rails/generators/rails/app/templates/config/databases/{jdbcpostgresql.yml → jdbcpostgresql.yml.tt} +0 -0
  113. data/lib/rails/generators/rails/app/templates/config/databases/{jdbcsqlite3.yml → jdbcsqlite3.yml.tt} +0 -0
  114. data/lib/rails/generators/rails/app/templates/config/databases/{mysql.yml → mysql.yml.tt} +1 -1
  115. data/lib/rails/generators/rails/app/templates/config/databases/{oracle.yml → oracle.yml.tt} +0 -0
  116. data/lib/rails/generators/rails/app/templates/config/databases/{postgresql.yml → postgresql.yml.tt} +0 -0
  117. data/lib/rails/generators/rails/app/templates/config/databases/{sqlite3.yml → sqlite3.yml.tt} +0 -0
  118. data/lib/rails/generators/rails/app/templates/config/databases/{sqlserver.yml → sqlserver.yml.tt} +2 -2
  119. data/lib/rails/generators/rails/app/templates/config/{environment.rb → environment.rb.tt} +0 -0
  120. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +7 -1
  121. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +12 -7
  122. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +8 -2
  123. data/lib/rails/generators/rails/app/templates/config/initializers/{application_controller_renderer.rb → application_controller_renderer.rb.tt} +0 -0
  124. data/lib/rails/generators/rails/app/templates/config/initializers/{backtrace_silencers.rb → backtrace_silencers.rb.tt} +0 -0
  125. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +20 -0
  126. data/lib/rails/generators/rails/app/templates/config/initializers/{cookies_serializer.rb → cookies_serializer.rb.tt} +0 -0
  127. data/lib/rails/generators/rails/app/templates/config/initializers/{cors.rb → cors.rb.tt} +0 -0
  128. data/lib/rails/generators/rails/app/templates/config/initializers/{filter_parameter_logging.rb → filter_parameter_logging.rb.tt} +0 -0
  129. data/lib/rails/generators/rails/app/templates/config/initializers/{inflections.rb → inflections.rb.tt} +0 -0
  130. data/lib/rails/generators/rails/app/templates/config/initializers/{mime_types.rb → mime_types.rb.tt} +0 -0
  131. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +27 -0
  132. data/lib/rails/generators/rails/app/templates/config/{puma.rb → puma.rb.tt} +0 -0
  133. data/lib/rails/generators/rails/app/templates/config/{routes.rb → routes.rb.tt} +0 -0
  134. data/lib/rails/generators/rails/app/templates/config/{spring.rb → spring.rb.tt} +2 -2
  135. data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +35 -0
  136. data/lib/rails/generators/rails/app/templates/{gitignore → gitignore.tt} +9 -1
  137. data/lib/rails/generators/rails/app/templates/{package.json → package.json.tt} +0 -0
  138. data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -0
  139. data/lib/rails/generators/rails/app/templates/test/{application_system_test_case.rb → application_system_test_case.rb.tt} +0 -0
  140. data/lib/rails/generators/rails/app/templates/test/{test_helper.rb → test_helper.rb.tt} +1 -2
  141. data/lib/rails/generators/rails/application_record/application_record_generator.rb +9 -0
  142. data/lib/rails/generators/rails/assets/assets_generator.rb +2 -0
  143. data/lib/rails/generators/rails/assets/templates/stylesheet.css +1 -1
  144. data/lib/rails/generators/rails/controller/controller_generator.rb +11 -9
  145. data/lib/rails/generators/rails/controller/templates/{controller.rb → controller.rb.tt} +0 -0
  146. data/lib/rails/generators/rails/credentials/credentials_generator.rb +48 -0
  147. data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +38 -0
  148. data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +57 -0
  149. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -0
  150. data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
  151. data/lib/rails/generators/rails/helper/helper_generator.rb +2 -0
  152. data/lib/rails/generators/rails/helper/templates/{helper.rb → helper.rb.tt} +0 -0
  153. data/lib/rails/generators/rails/integration_test/integration_test_generator.rb +2 -0
  154. data/lib/rails/generators/rails/master_key/master_key_generator.rb +51 -0
  155. data/lib/rails/generators/rails/migration/migration_generator.rb +2 -0
  156. data/lib/rails/generators/rails/model/model_generator.rb +2 -0
  157. data/lib/rails/generators/rails/plugin/plugin_generator.rb +18 -9
  158. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +24 -0
  159. data/lib/rails/generators/rails/plugin/templates/{Gemfile → Gemfile.tt} +1 -0
  160. data/lib/rails/generators/rails/plugin/templates/{MIT-LICENSE → MIT-LICENSE.tt} +0 -0
  161. data/lib/rails/generators/rails/plugin/templates/{README.md → README.md.tt} +1 -1
  162. data/lib/rails/generators/rails/plugin/templates/{Rakefile → Rakefile.tt} +6 -7
  163. data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +21 -4
  164. data/lib/rails/generators/rails/plugin/templates/bin/test.tt +1 -1
  165. data/lib/rails/generators/rails/plugin/templates/config/{routes.rb → routes.rb.tt} +0 -0
  166. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +18 -0
  167. data/lib/rails/generators/rails/plugin/templates/lib/{%namespaced_name%.rb → %namespaced_name%.rb.tt} +3 -1
  168. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/{engine.rb → engine.rb.tt} +0 -0
  169. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +5 -0
  170. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/{version.rb → version.rb.tt} +0 -0
  171. data/lib/rails/generators/rails/plugin/templates/lib/tasks/{%namespaced_name%_tasks.rake → %namespaced_name%_tasks.rake.tt} +0 -0
  172. data/lib/rails/generators/rails/plugin/templates/rails/{application.rb → application.rb.tt} +6 -3
  173. data/lib/rails/generators/rails/plugin/templates/rails/{boot.rb → boot.rb.tt} +0 -0
  174. data/lib/rails/generators/rails/plugin/templates/rails/{dummy_manifest.js → dummy_manifest.js.tt} +0 -1
  175. data/lib/rails/generators/rails/plugin/templates/rails/{engine_manifest.js → engine_manifest.js.tt} +0 -0
  176. data/lib/rails/generators/rails/plugin/templates/rails/{javascripts.js → javascripts.js.tt} +3 -0
  177. data/lib/rails/generators/rails/plugin/templates/rails/{routes.rb → routes.rb.tt} +0 -0
  178. data/lib/rails/generators/rails/plugin/templates/test/{%namespaced_name%_test.rb → %namespaced_name%_test.rb.tt} +0 -0
  179. data/lib/rails/generators/rails/plugin/templates/test/{application_system_test_case.rb → application_system_test_case.rb.tt} +0 -0
  180. data/lib/rails/generators/rails/plugin/templates/test/integration/{navigation_test.rb → navigation_test.rb.tt} +0 -1
  181. data/lib/rails/generators/rails/plugin/templates/test/{test_helper.rb → test_helper.rb.tt} +7 -6
  182. data/lib/rails/generators/rails/resource/USAGE +1 -1
  183. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -0
  184. data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +21 -24
  185. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -3
  186. data/lib/rails/generators/rails/scaffold_controller/USAGE +1 -1
  187. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -0
  188. data/lib/rails/generators/rails/scaffold_controller/templates/{api_controller.rb → api_controller.rb.tt} +0 -0
  189. data/lib/rails/generators/rails/scaffold_controller/templates/{controller.rb → controller.rb.tt} +2 -2
  190. data/lib/rails/generators/rails/system_test/system_test_generator.rb +2 -0
  191. data/lib/rails/generators/rails/task/task_generator.rb +2 -0
  192. data/lib/rails/generators/rails/task/templates/{task.rb → task.rb.tt} +0 -0
  193. data/lib/rails/generators/resource_helpers.rb +2 -0
  194. data/lib/rails/generators/test_case.rb +4 -2
  195. data/lib/rails/generators/test_unit.rb +2 -0
  196. data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
  197. data/lib/rails/generators/test_unit/controller/templates/{functional_test.rb → functional_test.rb.tt} +0 -0
  198. data/lib/rails/generators/test_unit/generator/generator_generator.rb +2 -0
  199. data/lib/rails/generators/test_unit/generator/templates/{generator_test.rb → generator_test.rb.tt} +0 -0
  200. data/lib/rails/generators/test_unit/helper/helper_generator.rb +2 -0
  201. data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -0
  202. data/lib/rails/generators/test_unit/integration/templates/{integration_test.rb → integration_test.rb.tt} +0 -0
  203. data/lib/rails/generators/test_unit/job/job_generator.rb +3 -1
  204. data/lib/rails/generators/test_unit/job/templates/{unit_test.rb.erb → unit_test.rb.tt} +0 -0
  205. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +2 -0
  206. data/lib/rails/generators/test_unit/mailer/templates/{functional_test.rb → functional_test.rb.tt} +0 -0
  207. data/lib/rails/generators/test_unit/mailer/templates/{preview.rb → preview.rb.tt} +0 -0
  208. data/lib/rails/generators/test_unit/model/model_generator.rb +2 -0
  209. data/lib/rails/generators/test_unit/model/templates/{fixtures.yml → fixtures.yml.tt} +0 -0
  210. data/lib/rails/generators/test_unit/model/templates/{unit_test.rb → unit_test.rb.tt} +0 -0
  211. data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -0
  212. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +17 -4
  213. data/lib/rails/generators/test_unit/scaffold/templates/{api_functional_test.rb → api_functional_test.rb.tt} +2 -2
  214. data/lib/rails/generators/test_unit/scaffold/templates/{functional_test.rb → functional_test.rb.tt} +2 -2
  215. data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +49 -0
  216. data/lib/rails/generators/test_unit/system/system_generator.rb +3 -1
  217. data/lib/rails/generators/test_unit/system/templates/{application_system_test_case.rb → application_system_test_case.rb.tt} +0 -0
  218. data/lib/rails/generators/test_unit/system/templates/{system_test.rb → system_test.rb.tt} +0 -0
  219. data/lib/rails/generators/testing/assertions.rb +7 -1
  220. data/lib/rails/generators/testing/behaviour.rb +8 -6
  221. data/lib/rails/generators/testing/setup_and_teardown.rb +2 -0
  222. data/lib/rails/info.rb +6 -3
  223. data/lib/rails/info_controller.rb +2 -0
  224. data/lib/rails/initializable.rb +2 -0
  225. data/lib/rails/mailers_controller.rb +9 -1
  226. data/lib/rails/paths.rb +2 -0
  227. data/lib/rails/plugin/test.rb +4 -2
  228. data/lib/rails/rack.rb +2 -0
  229. data/lib/rails/rack/logger.rb +5 -3
  230. data/lib/rails/railtie.rb +9 -4
  231. data/lib/rails/railtie/configurable.rb +2 -0
  232. data/lib/rails/railtie/configuration.rb +2 -0
  233. data/lib/rails/ruby_version_check.rb +3 -1
  234. data/lib/rails/secrets.rb +2 -17
  235. data/lib/rails/source_annotation_extractor.rb +4 -2
  236. data/lib/rails/tasks.rb +2 -0
  237. data/lib/rails/tasks/annotations.rake +2 -0
  238. data/lib/rails/tasks/dev.rake +2 -0
  239. data/lib/rails/tasks/engine.rake +7 -2
  240. data/lib/rails/tasks/framework.rake +9 -24
  241. data/lib/rails/tasks/initializers.rake +2 -0
  242. data/lib/rails/tasks/log.rake +2 -0
  243. data/lib/rails/tasks/middleware.rake +2 -0
  244. data/lib/rails/tasks/misc.rake +2 -0
  245. data/lib/rails/tasks/restart.rake +2 -1
  246. data/lib/rails/tasks/routes.rake +2 -0
  247. data/lib/rails/tasks/statistics.rake +2 -0
  248. data/lib/rails/tasks/tmp.rake +11 -2
  249. data/lib/rails/tasks/yarn.rake +3 -1
  250. data/lib/rails/templates/rails/mailers/email.html.erb +3 -3
  251. data/lib/rails/templates/rails/welcome/index.html.erb +14 -4
  252. data/lib/rails/test_help.rb +2 -0
  253. data/lib/rails/test_unit/line_filtering.rb +2 -1
  254. data/lib/rails/test_unit/railtie.rb +2 -0
  255. data/lib/rails/test_unit/reporter.rb +5 -10
  256. data/lib/rails/test_unit/runner.rb +3 -3
  257. data/lib/rails/test_unit/testing.rake +3 -1
  258. data/lib/rails/version.rb +2 -0
  259. data/lib/rails/welcome_controller.rb +2 -0
  260. metadata +121 -107
  261. data/lib/rails/generators/rails/app/templates/bin/bundle +0 -2
  262. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_1.rb.tt +0 -16
  263. data/lib/rails/generators/rails/app/templates/config/secrets.yml +0 -32
  264. data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +0 -70
  265. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +0 -33
  266. data/lib/rails/generators/rails/plugin/templates/gitignore +0 -9
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require "thor/group"
3
5
  rescue LoadError
@@ -16,6 +18,9 @@ module Rails
16
18
  include Thor::Actions
17
19
  include Rails::Generators::Actions
18
20
 
21
+ class_option :skip_namespace, type: :boolean, default: false,
22
+ desc: "Skip namespace (affects only isolated applications)"
23
+
19
24
  add_runtime_options!
20
25
  strict_args_position!
21
26
 
@@ -215,7 +220,7 @@ module Rails
215
220
  # Returns the base root for a common set of generators. This is used to dynamically
216
221
  # guess the default source root.
217
222
  def self.base_root
218
- File.dirname(__FILE__)
223
+ __dir__
219
224
  end
220
225
 
221
226
  # Cache source root and add lib/generators/base/generator/templates to
@@ -271,6 +276,40 @@ module Rails
271
276
  end
272
277
  end
273
278
 
279
+ # Wrap block with namespace of current application
280
+ # if namespace exists and is not skipped
281
+ def module_namespacing(&block) # :doc:
282
+ content = capture(&block)
283
+ content = wrap_with_namespace(content) if namespaced?
284
+ concat(content)
285
+ end
286
+
287
+ def indent(content, multiplier = 2) # :doc:
288
+ spaces = " " * multiplier
289
+ content.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join
290
+ end
291
+
292
+ def wrap_with_namespace(content) # :doc:
293
+ content = indent(content).chomp
294
+ "module #{namespace.name}\n#{content}\nend\n"
295
+ end
296
+
297
+ def namespace # :doc:
298
+ Rails::Generators.namespace
299
+ end
300
+
301
+ def namespaced? # :doc:
302
+ !options[:skip_namespace] && namespace
303
+ end
304
+
305
+ def namespace_dirs
306
+ @namespace_dirs ||= namespace.name.split("::").map(&:underscore)
307
+ end
308
+
309
+ def namespaced_path # :doc:
310
+ @namespaced_path ||= namespace_dirs.join("/")
311
+ end
312
+
274
313
  # Use Rails default banner.
275
314
  def self.banner # :doc:
276
315
  "rails generate #{namespace.sub(/^rails:/, '')} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ")
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators/named_base"
2
4
 
3
5
  module Css # :nodoc:
4
6
  module Generators # :nodoc:
5
7
  class AssetsGenerator < Rails::Generators::NamedBase # :nodoc:
6
- source_root File.expand_path("../templates", __FILE__)
8
+ source_root File.expand_path("templates", __dir__)
7
9
 
8
10
  def copy_stylesheet
9
11
  copy_file "stylesheet.css", File.join("app/assets/stylesheets", class_path, "#{file_name}.css")
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators/named_base"
2
4
 
3
5
  module Css # :nodoc:
4
6
  module Generators # :nodoc:
5
7
  class ScaffoldGenerator < Rails::Generators::NamedBase # :nodoc:
8
+ source_root Rails::Generators::ScaffoldGenerator.source_root
9
+
6
10
  # In order to allow the Sass generators to pick up the default Rails CSS and
7
11
  # transform it, we leave it in a standard location for the CSS stylesheet
8
12
  # generators to handle. For the simple, default case, just copy it over.
9
13
  def copy_stylesheet
10
- dir = Rails::Generators::ScaffoldGenerator.source_root
11
- file = File.join(dir, "scaffold.css")
12
- create_file "app/assets/stylesheets/scaffold.css", File.read(file)
14
+ copy_file "scaffold.css", "app/assets/stylesheets/scaffold.css"
13
15
  end
14
16
  end
15
17
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators/named_base"
2
4
 
3
5
  module Erb # :nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators/erb"
2
4
 
3
5
  module Erb # :nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators/erb"
2
4
 
3
5
  module Erb # :nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators/erb"
2
4
  require "rails/generators/resource_helpers"
3
5
 
@@ -1,4 +1,4 @@
1
- <%%= form_with(model: <%= singular_table_name %>, local: true) do |form| %>
1
+ <%%= form_with(model: <%= model_resource_name %>, local: true) do |form| %>
2
2
  <%% if <%= singular_table_name %>.errors.any? %>
3
3
  <div id="error_explanation">
4
4
  <h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
@@ -15,15 +15,15 @@
15
15
  <div class="field">
16
16
  <% if attribute.password_digest? -%>
17
17
  <%%= form.label :password %>
18
- <%%= form.password_field :password, id: :<%= field_id(:password) %> %>
18
+ <%%= form.password_field :password %>
19
19
  </div>
20
20
 
21
21
  <div class="field">
22
22
  <%%= form.label :password_confirmation %>
23
- <%%= form.password_field :password_confirmation, id: :<%= field_id(:password_confirmation) %> %>
23
+ <%%= form.password_field :password_confirmation %>
24
24
  <% else -%>
25
25
  <%%= form.label :<%= attribute.column_name %> %>
26
- <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, id: :<%= field_id(attribute.column_name) %> %>
26
+ <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %>
27
27
  <% end -%>
28
28
  </div>
29
29
 
@@ -18,9 +18,9 @@
18
18
  <% attributes.reject(&:password_digest?).each do |attribute| -%>
19
19
  <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
20
20
  <% end -%>
21
- <td><%%= link_to 'Show', <%= singular_table_name %> %></td>
22
- <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
23
- <td><%%= link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>
21
+ <td><%%= link_to 'Show', <%= model_resource_name %> %></td>
22
+ <td><%%= link_to 'Edit', edit_<%= singular_route_name %>_path(<%= singular_table_name %>) %></td>
23
+ <td><%%= link_to 'Destroy', <%= model_resource_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>
24
24
  </tr>
25
25
  <%% end %>
26
26
  </tbody>
@@ -28,4 +28,4 @@
28
28
 
29
29
  <br>
30
30
 
31
- <%%= link_to 'New <%= singular_table_name.titleize %>', new_<%= singular_table_name %>_path %>
31
+ <%%= link_to 'New <%= singular_table_name.titleize %>', new_<%= singular_route_name %>_path %>
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/time"
2
4
 
3
5
  module Rails
@@ -151,7 +153,7 @@ module Rails
151
153
  end
152
154
 
153
155
  def inject_options
154
- "".tap { |s| options_for_migration.each { |k, v| s << ", #{k}: #{v.inspect}" } }
156
+ "".dup.tap { |s| options_for_migration.each { |k, v| s << ", #{k}: #{v.inspect}" } }
155
157
  end
156
158
 
157
159
  def inject_index_options
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators/named_base"
2
4
 
3
5
  module Js # :nodoc:
4
6
  module Generators # :nodoc:
5
7
  class AssetsGenerator < Rails::Generators::NamedBase # :nodoc:
6
- source_root File.expand_path("../templates", __FILE__)
8
+ source_root File.expand_path("templates", __dir__)
7
9
 
8
10
  def copy_javascript
9
11
  copy_file "javascript.js", File.join("app/assets/javascripts", class_path, "#{file_name}.js")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/concern"
2
4
  require "rails/generators/actions/create_migration"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators/active_model"
2
4
 
3
5
  module Rails
@@ -1,4 +1,5 @@
1
- require "active_support/core_ext/module/introspection"
1
+ # frozen_string_literal: true
2
+
2
3
  require "rails/generators/base"
3
4
  require "rails/generators/generated_attribute"
4
5
 
@@ -6,8 +7,6 @@ module Rails
6
7
  module Generators
7
8
  class NamedBase < Base
8
9
  argument :name, type: :string
9
- class_option :skip_namespace, type: :boolean, default: false,
10
- desc: "Skip namespace (affects only isolated applications)"
11
10
 
12
11
  def initialize(args, *options) #:nodoc:
13
12
  @inside_template = nil
@@ -45,24 +44,6 @@ module Rails
45
44
  file_name
46
45
  end
47
46
 
48
- # Wrap block with namespace of current application
49
- # if namespace exists and is not skipped
50
- def module_namespacing(&block) # :doc:
51
- content = capture(&block)
52
- content = wrap_with_namespace(content) if namespaced?
53
- concat(content)
54
- end
55
-
56
- def indent(content, multiplier = 2) # :doc:
57
- spaces = " " * multiplier
58
- content.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join
59
- end
60
-
61
- def wrap_with_namespace(content) # :doc:
62
- content = indent(content).chomp
63
- "module #{namespace.name}\n#{content}\nend\n"
64
- end
65
-
66
47
  def inside_template # :doc:
67
48
  @inside_template = true
68
49
  yield
@@ -74,18 +55,6 @@ module Rails
74
55
  @inside_template
75
56
  end
76
57
 
77
- def namespace # :doc:
78
- Rails::Generators.namespace
79
- end
80
-
81
- def namespaced? # :doc:
82
- !options[:skip_namespace] && namespace
83
- end
84
-
85
- def namespace_dirs
86
- @namespace_dirs ||= namespace.name.split("::").map(&:underscore)
87
- end
88
-
89
58
  def file_path # :doc:
90
59
  @file_path ||= (class_path + [file_name]).join("/")
91
60
  end
@@ -102,10 +71,6 @@ module Rails
102
71
  @namespaced_class_path ||= namespace_dirs + @class_path
103
72
  end
104
73
 
105
- def namespaced_path # :doc:
106
- @namespaced_path ||= namespace_dirs.join("/")
107
- end
108
-
109
74
  def class_name # :doc:
110
75
  (class_path + [file_name]).map!(&:camelize).join("::")
111
76
  end
@@ -134,11 +99,11 @@ module Rails
134
99
  end
135
100
 
136
101
  def index_helper # :doc:
137
- uncountable? ? "#{plural_table_name}_index" : plural_table_name
102
+ uncountable? ? "#{plural_route_name}_index" : plural_route_name
138
103
  end
139
104
 
140
105
  def show_helper # :doc:
141
- "#{singular_table_name}_url(@#{singular_table_name})"
106
+ "#{singular_route_name}_url(@#{singular_table_name})"
142
107
  end
143
108
 
144
109
  def edit_helper # :doc:
@@ -146,11 +111,7 @@ module Rails
146
111
  end
147
112
 
148
113
  def new_helper # :doc:
149
- "new_#{singular_table_name}_url"
150
- end
151
-
152
- def field_id(attribute_name)
153
- [singular_table_name, attribute_name].join("_")
114
+ "new_#{singular_route_name}_url"
154
115
  end
155
116
 
156
117
  def singular_table_name # :doc:
@@ -186,6 +147,35 @@ module Rails
186
147
  end
187
148
  end
188
149
 
150
+ def redirect_resource_name # :doc:
151
+ model_resource_name(prefix: "@")
152
+ end
153
+
154
+ def model_resource_name(prefix: "") # :doc:
155
+ resource_name = "#{prefix}#{singular_table_name}"
156
+ if options[:model_name]
157
+ "[#{controller_class_path.map { |name| ":" + name }.join(", ")}, #{resource_name}]"
158
+ else
159
+ resource_name
160
+ end
161
+ end
162
+
163
+ def singular_route_name # :doc:
164
+ if options[:model_name]
165
+ "#{controller_class_path.join('_')}_#{singular_table_name}"
166
+ else
167
+ singular_table_name
168
+ end
169
+ end
170
+
171
+ def plural_route_name # :doc:
172
+ if options[:model_name]
173
+ "#{controller_class_path.join('_')}_#{plural_table_name}"
174
+ else
175
+ plural_table_name
176
+ end
177
+ end
178
+
189
179
  def assign_names!(name)
190
180
  @class_path = name.include?("/") ? name.split("/") : name.split("::")
191
181
  @class_path.map!(&:underscore)
@@ -227,7 +217,7 @@ module Rails
227
217
  #
228
218
  def self.check_class_collision(options = {}) # :doc:
229
219
  define_method :check_class_collision do
230
- name = if respond_to?(:controller_class_name) # for ScaffoldBase
220
+ name = if respond_to?(:controller_class_name) # for ResourceHelpers
231
221
  controller_class_name
232
222
  else
233
223
  class_name
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators/app_base"
2
4
 
3
5
  module Rails
@@ -49,6 +51,10 @@ module Rails
49
51
  copy_file "README.md", "README.md"
50
52
  end
51
53
 
54
+ def ruby_version
55
+ template "ruby-version", ".ruby-version"
56
+ end
57
+
52
58
  def gemfile
53
59
  template "Gemfile"
54
60
  end
@@ -63,10 +69,14 @@ module Rails
63
69
 
64
70
  def version_control
65
71
  if !options[:skip_git] && !options[:pretend]
66
- run "git init"
72
+ run "git init", capture: options[:quiet]
67
73
  end
68
74
  end
69
75
 
76
+ def package_json
77
+ template "package.json"
78
+ end
79
+
70
80
  def app
71
81
  directory "app"
72
82
 
@@ -101,10 +111,10 @@ module Rails
101
111
  template "routes.rb"
102
112
  template "application.rb"
103
113
  template "environment.rb"
104
- template "secrets.yml"
105
114
  template "cable.yml" unless options[:skip_action_cable]
106
115
  template "puma.rb" unless options[:skip_puma]
107
116
  template "spring.rb" if spring_install?
117
+ template "storage.yml" unless skip_active_storage?
108
118
 
109
119
  directory "environments"
110
120
  directory "initializers"
@@ -114,10 +124,11 @@ module Rails
114
124
 
115
125
  def config_when_updating
116
126
  cookie_serializer_config_exist = File.exist?("config/initializers/cookies_serializer.rb")
117
- action_cable_config_exist = File.exist?("config/cable.yml")
118
- rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
119
- assets_config_exist = File.exist?("config/initializers/assets.rb")
120
- new_framework_defaults_5_1_exist = File.exist?("config/initializers/new_framework_defaults_5_1.rb")
127
+ action_cable_config_exist = File.exist?("config/cable.yml")
128
+ active_storage_config_exist = File.exist?("config/storage.yml")
129
+ rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
130
+ assets_config_exist = File.exist?("config/initializers/assets.rb")
131
+ csp_config_exist = File.exist?("config/initializers/content_security_policy.rb")
121
132
 
122
133
  config
123
134
 
@@ -125,10 +136,14 @@ module Rails
125
136
  gsub_file "config/initializers/cookies_serializer.rb", /json(?!,)/, "marshal"
126
137
  end
127
138
 
128
- unless action_cable_config_exist
139
+ if !options[:skip_action_cable] && !action_cable_config_exist
129
140
  template "config/cable.yml"
130
141
  end
131
142
 
143
+ if !skip_active_storage? && !active_storage_config_exist
144
+ template "config/storage.yml"
145
+ end
146
+
132
147
  unless rack_cors_config_exist
133
148
  remove_file "config/initializers/cors.rb"
134
149
  end
@@ -142,14 +157,28 @@ module Rails
142
157
  remove_file "config/initializers/assets.rb"
143
158
  end
144
159
 
145
- # Sprockets owns the only new default for 5.1:
146
- # In API-only Applications, we don't want the file.
147
- unless new_framework_defaults_5_1_exist
148
- remove_file "config/initializers/new_framework_defaults_5_1.rb"
160
+ unless csp_config_exist
161
+ remove_file "config/initializers/content_security_policy.rb"
149
162
  end
150
163
  end
151
164
  end
152
165
 
166
+ def master_key
167
+ return if options[:pretend] || options[:dummy_app]
168
+
169
+ require "rails/generators/rails/master_key/master_key_generator"
170
+ master_key_generator = Rails::Generators::MasterKeyGenerator.new([], quiet: options[:quiet])
171
+ master_key_generator.add_master_key_file_silently
172
+ master_key_generator.ignore_master_key_file_silently
173
+ end
174
+
175
+ def credentials
176
+ return if options[:pretend] || options[:dummy_app]
177
+
178
+ require "rails/generators/rails/credentials/credentials_generator"
179
+ Rails::Generators::CredentialsGenerator.new([], quiet: options[:quiet]).add_credentials_file_silently
180
+ end
181
+
153
182
  def database_yml
154
183
  template "config/databases/#{options[:database]}.yml", "config/database.yml"
155
184
  end
@@ -172,6 +201,11 @@ module Rails
172
201
  directory "public", "public", recursive: false
173
202
  end
174
203
 
204
+ def storage
205
+ empty_directory_with_keep_file "storage"
206
+ empty_directory_with_keep_file "tmp/storage"
207
+ end
208
+
175
209
  def test
176
210
  empty_directory_with_keep_file "test/fixtures"
177
211
  empty_directory_with_keep_file "test/fixtures/files"
@@ -198,21 +232,17 @@ module Rails
198
232
 
199
233
  def vendor
200
234
  empty_directory_with_keep_file "vendor"
201
-
202
- unless options[:skip_yarn]
203
- template "package.json"
204
- end
205
235
  end
206
236
  end
207
237
 
208
238
  module Generators
209
239
  # We need to store the RAILS_DEV_PATH in a constant, otherwise the path
210
240
  # can change in Ruby 1.8.7 when we FileUtils.cd.
211
- RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__))
241
+ RAILS_DEV_PATH = File.expand_path("../../../../../..", __dir__)
212
242
  RESERVED_NAMES = %w[application destroy plugin runner test]
213
243
 
214
244
  class AppGenerator < AppBase # :nodoc:
215
- WEBPACKS = %w( react vue angular )
245
+ WEBPACKS = %w( react vue angular elm )
216
246
 
217
247
  add_shared_options_for "application"
218
248
 
@@ -249,10 +279,12 @@ module Rails
249
279
  def create_root_files
250
280
  build(:readme)
251
281
  build(:rakefile)
282
+ build(:ruby_version)
252
283
  build(:configru)
253
284
  build(:gitignore) unless options[:skip_git]
254
285
  build(:gemfile) unless options[:skip_gemfile]
255
286
  build(:version_control)
287
+ build(:package_json) unless options[:skip_yarn]
256
288
  end
257
289
 
258
290
  def create_app_files
@@ -277,6 +309,14 @@ module Rails
277
309
  end
278
310
  remove_task :update_config_files
279
311
 
312
+ def create_master_key
313
+ build(:master_key)
314
+ end
315
+
316
+ def create_credentials
317
+ build(:credentials)
318
+ end
319
+
280
320
  def display_upgrade_guide_info
281
321
  say "\nAfter this, check Rails upgrade guide at http://guides.rubyonrails.org/upgrading_ruby_on_rails.html for more details about upgrading your app."
282
322
  end
@@ -316,6 +356,10 @@ module Rails
316
356
  build(:system_test) if depends_on_system_test?
317
357
  end
318
358
 
359
+ def create_storage_files
360
+ build(:storage) unless skip_active_storage?
361
+ end
362
+
319
363
  def create_tmp_files
320
364
  build(:tmp)
321
365
  end
@@ -385,7 +429,6 @@ module Rails
385
429
 
386
430
  def delete_action_cable_files_skipping_action_cable
387
431
  if options[:skip_action_cable]
388
- remove_file "config/cable.yml"
389
432
  remove_file "app/assets/javascripts/cable.js"
390
433
  remove_dir "app/channels"
391
434
  end
@@ -394,6 +437,7 @@ module Rails
394
437
  def delete_non_api_initializers_if_api_option
395
438
  if options[:api]
396
439
  remove_file "config/initializers/cookies_serializer.rb"
440
+ remove_file "config/initializers/content_security_policy.rb"
397
441
  end
398
442
  end
399
443
 
@@ -405,7 +449,7 @@ module Rails
405
449
 
406
450
  def delete_new_framework_defaults
407
451
  unless options[:update]
408
- remove_file "config/initializers/new_framework_defaults_5_1.rb"
452
+ remove_file "config/initializers/new_framework_defaults_5_2.rb"
409
453
  end
410
454
  end
411
455
 
@@ -419,6 +463,7 @@ module Rails
419
463
 
420
464
  public_task :apply_rails_template, :run_bundle
421
465
  public_task :run_webpack, :generate_spring_binstubs
466
+ public_task :run_active_storage
422
467
 
423
468
  def run_after_bundle_callbacks
424
469
  @after_bundle_callbacks.each(&:call)
@@ -471,10 +516,6 @@ module Rails
471
516
  end
472
517
  end
473
518
 
474
- def app_secret
475
- SecureRandom.hex(64)
476
- end
477
-
478
519
  def mysql_socket
479
520
  @mysql_socket ||= [
480
521
  "/tmp/mysql.sock", # default