railties 5.2.6.2 → 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.

Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +183 -199
  3. data/MIT-LICENSE +1 -1
  4. data/RDOC_MAIN.rdoc +35 -28
  5. data/README.rdoc +1 -1
  6. data/lib/minitest/rails_plugin.rb +6 -10
  7. data/lib/rails/all.rb +4 -0
  8. data/lib/rails/api/generator.rb +2 -1
  9. data/lib/rails/api/task.rb +16 -0
  10. data/lib/rails/app_loader.rb +1 -1
  11. data/lib/rails/app_updater.rb +3 -1
  12. data/lib/rails/application/configuration.rb +54 -12
  13. data/lib/rails/application/default_middleware_stack.rb +2 -0
  14. data/lib/rails/application.rb +21 -45
  15. data/lib/rails/backtrace_cleaner.rb +5 -17
  16. data/lib/rails/code_statistics.rb +3 -3
  17. data/lib/rails/command/actions.rb +0 -10
  18. data/lib/rails/command/base.rb +1 -5
  19. data/lib/rails/command/behavior.rb +4 -46
  20. data/lib/rails/command/environment_argument.rb +1 -11
  21. data/lib/rails/command/spellchecker.rb +58 -0
  22. data/lib/rails/command.rb +11 -10
  23. data/lib/rails/commands/credentials/USAGE +19 -1
  24. data/lib/rails/commands/credentials/credentials_command.rb +42 -23
  25. data/lib/rails/commands/db/system/change/change_command.rb +20 -0
  26. data/lib/rails/commands/dbconsole/dbconsole_command.rb +2 -2
  27. data/lib/rails/commands/dev/dev_command.rb +17 -0
  28. data/lib/rails/commands/encrypted/encrypted_command.rb +2 -3
  29. data/lib/rails/commands/help/help_command.rb +1 -1
  30. data/lib/rails/commands/initializers/initializers_command.rb +16 -0
  31. data/lib/rails/commands/new/new_command.rb +2 -2
  32. data/lib/rails/commands/notes/notes_command.rb +39 -0
  33. data/lib/rails/commands/plugin/plugin_command.rb +1 -1
  34. data/lib/rails/commands/routes/routes_command.rb +37 -0
  35. data/lib/rails/commands/runner/runner_command.rb +6 -6
  36. data/lib/rails/commands/secrets/USAGE +3 -3
  37. data/lib/rails/commands/secrets/secrets_command.rb +3 -3
  38. data/lib/rails/commands/server/server_command.rb +109 -48
  39. data/lib/rails/configuration.rb +1 -7
  40. data/lib/rails/engine/configuration.rb +3 -1
  41. data/lib/rails/engine.rb +3 -9
  42. data/lib/rails/gem_version.rb +4 -4
  43. data/lib/rails/generators/actions.rb +48 -37
  44. data/lib/rails/generators/app_base.rb +49 -89
  45. data/lib/rails/generators/app_name.rb +50 -0
  46. data/lib/rails/generators/base.rb +0 -4
  47. data/lib/rails/generators/database.rb +57 -0
  48. data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -1
  49. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
  50. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +1 -1
  51. data/lib/rails/generators/generated_attribute.rb +17 -17
  52. data/lib/rails/generators/model_helpers.rb +8 -1
  53. data/lib/rails/generators/named_base.rb +1 -5
  54. data/lib/rails/generators/rails/app/app_generator.rb +37 -72
  55. data/lib/rails/generators/rails/app/templates/Gemfile.tt +3 -6
  56. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
  57. data/lib/rails/generators/rails/app/templates/app/{assets/javascripts/cable.js.tt → javascript/channels/consumer.js} +2 -9
  58. data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
  59. data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +15 -0
  60. data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
  61. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
  62. data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -5
  63. data/lib/rails/generators/rails/app/templates/bin/update.tt +6 -7
  64. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +2 -0
  65. data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
  66. data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +2 -2
  67. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +2 -2
  68. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
  69. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
  70. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +3 -3
  71. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +4 -4
  72. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
  73. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +6 -6
  74. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -2
  76. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +5 -12
  77. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +6 -2
  78. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -1
  79. data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +4 -0
  80. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +33 -0
  81. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
  82. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +3 -5
  83. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
  84. data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
  85. data/lib/rails/generators/rails/app/templates/gitignore.tt +2 -7
  86. data/lib/rails/generators/rails/app/templates/package.json.tt +7 -1
  87. data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
  88. data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
  89. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +7 -0
  90. data/lib/rails/generators/rails/assets/USAGE +1 -4
  91. data/lib/rails/generators/rails/assets/assets_generator.rb +0 -8
  92. data/lib/rails/generators/rails/controller/controller_generator.rb +11 -1
  93. data/lib/rails/generators/rails/credentials/credentials_generator.rb +7 -8
  94. data/lib/rails/generators/rails/db/system/change/change_generator.rb +55 -0
  95. data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +4 -5
  96. data/lib/rails/generators/rails/helper/helper_generator.rb +5 -0
  97. data/lib/rails/generators/rails/plugin/plugin_generator.rb +9 -18
  98. data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +1 -1
  99. data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
  100. data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
  101. data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
  102. data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
  103. data/lib/rails/generators/rails/plugin/templates/gitignore.tt +1 -1
  104. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
  105. data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
  106. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +1 -2
  107. data/lib/rails/generators/resource_helpers.rb +1 -6
  108. data/lib/rails/generators/test_unit/integration/integration_generator.rb +6 -0
  109. data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
  110. data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +1 -1
  111. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +1 -1
  112. data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
  113. data/lib/rails/generators/testing/behaviour.rb +3 -0
  114. data/lib/rails/generators.rb +11 -12
  115. data/lib/rails/info.rb +2 -2
  116. data/lib/rails/info_controller.rb +1 -1
  117. data/lib/rails/mailers_controller.rb +1 -1
  118. data/lib/rails/paths.rb +19 -9
  119. data/lib/rails/railtie.rb +1 -1
  120. data/lib/rails/ruby_version_check.rb +3 -3
  121. data/lib/rails/secrets.rb +0 -1
  122. data/lib/rails/source_annotation_extractor.rb +125 -117
  123. data/lib/rails/tasks/annotations.rake +9 -9
  124. data/lib/rails/tasks/dev.rake +5 -4
  125. data/lib/rails/tasks/framework.rake +5 -1
  126. data/lib/rails/tasks/initializers.rake +5 -4
  127. data/lib/rails/tasks/log.rake +0 -1
  128. data/lib/rails/tasks/routes.rake +4 -26
  129. data/lib/rails/tasks/statistics.rake +1 -0
  130. data/lib/rails/tasks/yarn.rake +1 -1
  131. data/lib/rails/templates/rails/welcome/index.html.erb +2 -2
  132. data/lib/rails/test_help.rb +11 -9
  133. data/lib/rails/test_unit/reporter.rb +1 -1
  134. data/lib/rails/test_unit/runner.rb +5 -5
  135. data/lib/rails/test_unit/testing.rake +1 -1
  136. metadata +33 -27
  137. data/lib/rails/commands/encrypted/USAGE +0 -28
  138. data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
  139. data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
  140. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
  141. data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
  142. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_5_2.rb.tt +0 -38
  143. data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "fileutils"
4
4
  require "digest/md5"
5
- require "active_support/core_ext/string/strip"
6
5
  require "rails/version" unless defined?(Rails::VERSION)
7
6
  require "open-uri"
8
7
  require "uri"
@@ -12,9 +11,8 @@ require "active_support/core_ext/array/extract_options"
12
11
  module Rails
13
12
  module Generators
14
13
  class AppBase < Base # :nodoc:
15
- DATABASES = %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver )
16
- JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )
17
- DATABASES.concat(JDBC_DATABASES)
14
+ include Database
15
+ include AppName
18
16
 
19
17
  attr_accessor :rails_template
20
18
  add_shebang_option!
@@ -32,9 +30,6 @@ module Rails
32
30
  class_option :database, type: :string, aliases: "-d", default: "sqlite3",
33
31
  desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
34
32
 
35
- class_option :skip_yarn, type: :boolean, default: false,
36
- desc: "Don't use Yarn for managing JavaScript dependencies"
37
-
38
33
  class_option :skip_gemfile, type: :boolean, default: false,
39
34
  desc: "Don't create a Gemfile"
40
35
 
@@ -48,6 +43,12 @@ module Rails
48
43
  default: false,
49
44
  desc: "Skip Action Mailer files"
50
45
 
46
+ class_option :skip_action_mailbox, type: :boolean, default: false,
47
+ desc: "Skip Action Mailbox gem"
48
+
49
+ class_option :skip_action_text, type: :boolean, default: false,
50
+ desc: "Skip Action Text gem"
51
+
51
52
  class_option :skip_active_record, type: :boolean, aliases: "-O", default: false,
52
53
  desc: "Skip Active Record files"
53
54
 
@@ -69,10 +70,7 @@ module Rails
69
70
  class_option :skip_listen, type: :boolean, default: false,
70
71
  desc: "Don't generate configuration that depends on the listen gem"
71
72
 
72
- class_option :skip_coffee, type: :boolean, default: false,
73
- desc: "Don't use CoffeeScript"
74
-
75
- class_option :skip_javascript, type: :boolean, aliases: "-J", default: false,
73
+ class_option :skip_javascript, type: :boolean, aliases: "-J", default: name == "plugin",
76
74
  desc: "Skip JavaScript files"
77
75
 
78
76
  class_option :skip_turbolinks, type: :boolean, default: false,
@@ -107,7 +105,6 @@ module Rails
107
105
  @gem_filter = lambda { |gem| true }
108
106
  @extra_entries = []
109
107
  super
110
- convert_database_option_for_jruby
111
108
  end
112
109
 
113
110
  private
@@ -207,7 +204,9 @@ module Rails
207
204
  :skip_sprockets,
208
205
  :skip_action_cable
209
206
  ),
210
- skip_active_storage?
207
+ skip_active_storage?,
208
+ skip_action_mailbox?,
209
+ skip_action_text?
211
210
  ].flatten.none?
212
211
  end
213
212
 
@@ -236,6 +235,14 @@ module Rails
236
235
  options[:skip_active_storage] || options[:skip_active_record]
237
236
  end
238
237
 
238
+ def skip_action_mailbox? # :doc:
239
+ options[:skip_action_mailbox] || skip_active_storage?
240
+ end
241
+
242
+ def skip_action_text? # :doc:
243
+ options[:skip_action_text] || skip_active_storage?
244
+ end
245
+
239
246
  class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out)
240
247
  def initialize(name, version, comment, options = {}, commented_out = false)
241
248
  super
@@ -275,7 +282,7 @@ module Rails
275
282
  ]
276
283
  elsif options.edge?
277
284
  [
278
- GemfileEntry.github("rails", "rails/rails", "5-2-stable")
285
+ GemfileEntry.github("rails", "rails/rails")
279
286
  ]
280
287
  else
281
288
  [GemfileEntry.version("rails",
@@ -297,55 +304,20 @@ module Rails
297
304
  end
298
305
  end
299
306
 
300
- def gem_for_database
301
- # %w( mysql postgresql sqlite3 oracle frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql )
302
- case options[:database]
303
- when "mysql" then ["mysql2", [">= 0.4.4", "< 0.6.0"]]
304
- when "postgresql" then ["pg", [">= 0.18", "< 2.0"]]
305
- when "oracle" then ["activerecord-oracle_enhanced-adapter", nil]
306
- when "frontbase" then ["ruby-frontbase", nil]
307
- when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
308
- when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil]
309
- when "jdbcsqlite3" then ["activerecord-jdbcsqlite3-adapter", nil]
310
- when "jdbcpostgresql" then ["activerecord-jdbcpostgresql-adapter", nil]
311
- when "jdbc" then ["activerecord-jdbc-adapter", nil]
312
- else [options[:database], nil]
313
- end
314
- end
315
-
316
- def convert_database_option_for_jruby
317
- if defined?(JRUBY_VERSION)
318
- opt = options.dup
319
- case opt[:database]
320
- when "postgresql" then opt[:database] = "jdbcpostgresql"
321
- when "mysql" then opt[:database] = "jdbcmysql"
322
- when "sqlite3" then opt[:database] = "jdbcsqlite3"
323
- end
324
- self.options = opt.freeze
325
- end
326
- end
327
-
328
307
  def assets_gemfile_entry
329
308
  return [] if options[:skip_sprockets]
330
309
 
331
- gems = []
332
- gems << GemfileEntry.version("sass-rails", "~> 5.0",
333
- "Use SCSS for stylesheets")
334
-
335
- if !options[:skip_javascript]
336
- gems << GemfileEntry.version("uglifier",
337
- ">= 1.3.0",
338
- "Use Uglifier as compressor for JavaScript assets")
339
- end
340
-
341
- gems
310
+ GemfileEntry.version("sass-rails", "~> 5.0", "Use SCSS for stylesheets")
342
311
  end
343
312
 
344
313
  def webpacker_gemfile_entry
345
- return [] unless options[:webpack]
314
+ return [] if options[:skip_javascript]
346
315
 
347
- comment = "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker"
348
- GemfileEntry.new "webpacker", nil, comment
316
+ if options.dev? || options.edge?
317
+ GemfileEntry.github "webpacker", "rails/webpacker", nil, "Use development version of Webpacker"
318
+ else
319
+ GemfileEntry.version "webpacker", ">= 4.0.0.rc.3", "Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker"
320
+ end
349
321
  end
350
322
 
351
323
  def jbuilder_gemfile_entry
@@ -353,34 +325,12 @@ module Rails
353
325
  GemfileEntry.new "jbuilder", "~> 2.5", comment, {}, options[:api]
354
326
  end
355
327
 
356
- def coffee_gemfile_entry
357
- GemfileEntry.version "coffee-rails", "~> 4.2", "Use CoffeeScript for .coffee assets and views"
358
- end
359
-
360
328
  def javascript_gemfile_entry
361
- if options[:skip_javascript] || options[:skip_sprockets]
329
+ if options[:skip_javascript] || options[:skip_turbolinks]
362
330
  []
363
331
  else
364
- gems = [javascript_runtime_gemfile_entry]
365
- gems << coffee_gemfile_entry unless options[:skip_coffee]
366
-
367
- unless options[:skip_turbolinks]
368
- gems << GemfileEntry.version("turbolinks", "~> 5",
369
- "Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks")
370
- end
371
-
372
- gems
373
- end
374
- end
375
-
376
- def javascript_runtime_gemfile_entry
377
- comment = "See https://github.com/rails/execjs#readme for more supported runtimes"
378
- if defined?(JRUBY_VERSION)
379
- GemfileEntry.version "therubyrhino", nil, comment
380
- elsif RUBY_PLATFORM =~ /mingw|mswin/
381
- GemfileEntry.version "duktape", nil, comment
382
- else
383
- GemfileEntry.new "mini_racer", nil, comment, { platforms: :ruby }, true
332
+ [ GemfileEntry.version("turbolinks", "~> 5",
333
+ "Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks") ]
384
334
  end
385
335
  end
386
336
 
@@ -400,7 +350,7 @@ module Rails
400
350
  gems
401
351
  end
402
352
 
403
- def bundle_command(command)
353
+ def bundle_command(command, env = {})
404
354
  say_status :run, "bundle #{command}"
405
355
 
406
356
  # We are going to shell out rather than invoking Bundler::CLI.new(command)
@@ -413,16 +363,16 @@ module Rails
413
363
 
414
364
  require "bundler"
415
365
  Bundler.with_original_env do
416
- exec_bundle_command(_bundle_command, command)
366
+ exec_bundle_command(_bundle_command, command, env)
417
367
  end
418
368
  end
419
369
 
420
- def exec_bundle_command(bundle_command, command)
370
+ def exec_bundle_command(bundle_command, command, env)
421
371
  full_command = %Q["#{Gem.ruby}" "#{bundle_command}" #{command}]
422
372
  if options[:quiet]
423
- system(full_command, out: File::NULL)
373
+ system(env, full_command, out: File::NULL)
424
374
  else
425
- system(full_command)
375
+ system(env, full_command)
426
376
  end
427
377
  end
428
378
 
@@ -434,6 +384,10 @@ module Rails
434
384
  !options[:skip_spring] && !options.dev? && Process.respond_to?(:fork) && !RUBY_PLATFORM.include?("cygwin")
435
385
  end
436
386
 
387
+ def webpack_install?
388
+ !(options[:skip_javascript] || options[:skip_webpack_install])
389
+ end
390
+
437
391
  def depends_on_system_test?
438
392
  !(options[:skip_system_test] || options[:skip_test] || options[:api])
439
393
  end
@@ -451,13 +405,19 @@ module Rails
451
405
  end
452
406
 
453
407
  def run_bundle
454
- bundle_command("install") if bundle_install?
408
+ bundle_command("install", "BUNDLE_IGNORE_MESSAGES" => "1") if bundle_install?
455
409
  end
456
410
 
457
411
  def run_webpack
458
- if !(webpack = options[:webpack]).nil?
412
+ if webpack_install?
459
413
  rails_command "webpacker:install"
460
- rails_command "webpacker:install:#{webpack}" unless webpack == "webpack"
414
+ rails_command "webpacker:install:#{options[:webpack]}" if options[:webpack] && options[:webpack] != "webpack"
415
+ end
416
+ end
417
+
418
+ def generate_bundler_binstub
419
+ if bundle_install?
420
+ bundle_command("binstubs bundler")
461
421
  end
462
422
  end
463
423
 
@@ -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
@@ -24,10 +24,6 @@ module Rails
24
24
  add_runtime_options!
25
25
  strict_args_position!
26
26
 
27
- def self.exit_on_failure? # :nodoc:
28
- false
29
- end
30
-
31
27
  # Returns the source root for this generator using default_source_root as default.
32
28
  def self.source_root(path = nil)
33
29
  @_source_root = path if path
@@ -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
@@ -35,7 +35,7 @@ module Erb # :nodoc:
35
35
  end
36
36
 
37
37
  def file_name
38
- @_file_name ||= super.gsub(/_mailer/i, "")
38
+ @_file_name ||= super.sub(/_mailer\z/i, "")
39
39
  end
40
40
  end
41
41
  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.name %> %></td>
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.name %> %>
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
- # 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, {}
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
- "".dup.tap { |s| options_for_migration.each { |k, v| s << ", #{k}: #{v.inspect}" } }
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.