Class: Rails::Generators::AppGenerator
- Inherits:
-
AppBase
- Object
- Thor::Group
- Base
- AppBase
- Rails::Generators::AppGenerator
show all
- Defined in:
- lib/rails/commands/application/application_command.rb,
lib/rails/generators/rails/app/app_generator.rb
Overview
Constant Summary
Constants included
from AppName
Rails::Generators::AppName::RESERVED_NAMES
Constants included
from Database
Database::DATABASES, Database::JDBC_DATABASES
Instance Attribute Summary
Attributes inherited from AppBase
#rails_template
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from AppBase
add_shared_options_for, strict_args_position
Methods included from Database
#convert_database_option_for_jruby, #gem_for_database
Methods inherited from Base
base_root, class_option, default_source_root, desc, hide!, hook_for, inherited, namespace, remove_hook_for, source_root
Methods included from Actions
#add_source, #environment, #gem, #gem_group, #generate, #git, #github, #initializer, #lib, #rails_command, #rake, #rakefile, #readme, #route, #vendor
Constructor Details
Returns a new instance of AppGenerator.
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 280
def initialize(*args)
super
if !options[:skip_active_record] && !DATABASES.include?(options[:database])
raise Error, "Invalid value for --database option. Supported preconfigurations are: #{DATABASES.join(", ")}."
end
if options[:api]
self.options = options.merge(skip_asset_pipeline: true, skip_javascript: true).freeze
end
if options[:minimal]
self.options = options.merge(
skip_action_cable: true,
skip_action_mailer: true,
skip_action_mailbox: true,
skip_action_text: true,
skip_active_job: true,
skip_active_storage: true,
skip_bootsnap: true,
skip_dev_gems: true,
skip_javascript: true,
skip_jbuilder: true,
skip_system_test: true,
skip_hotwire: true).freeze
end
@after_bundle_callbacks = []
end
|
Class Method Details
.banner ⇒ Object
535
536
537
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 535
def self.banner
"rails new #{arguments.map(&:usage).join(' ')} [options]"
end
|
.exit_on_failure? ⇒ Boolean
We want to exit on failure to be kind to other libraries This is only when accessing via CLI
11
12
13
|
# File 'lib/rails/commands/application/application_command.rb', line 11
def self.exit_on_failure?
true
end
|
Instance Method Details
#create_active_record_files ⇒ Object
382
383
384
385
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 382
def create_active_record_files
return if options[:skip_active_record]
build(:database_yml)
end
|
#create_app_files ⇒ Object
331
332
333
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 331
def create_app_files
build(:app)
end
|
#create_bin_files ⇒ Object
335
336
337
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 335
def create_bin_files
build(:bin)
end
|
#create_boot_file ⇒ Object
378
379
380
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 378
def create_boot_file
template "config/boot.rb"
end
|
#create_config_files ⇒ Object
356
357
358
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 356
def create_config_files
build(:config)
end
|
#create_credentials ⇒ Object
369
370
371
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 369
def create_credentials
build(:credentials)
end
|
#create_db_files ⇒ Object
387
388
389
390
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 387
def create_db_files
return if options[:skip_active_record]
build(:db)
end
|
#create_lib_files ⇒ Object
392
393
394
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 392
def create_lib_files
build(:lib)
end
|
#create_log_files ⇒ Object
396
397
398
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 396
def create_log_files
build(:log)
end
|
#create_master_key ⇒ Object
365
366
367
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 365
def create_master_key
build(:master_key)
end
|
#create_public_files ⇒ Object
400
401
402
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 400
def create_public_files
build(:public_directory)
end
|
#create_root_files ⇒ Object
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 316
def create_root_files
build(:readme)
build(:rakefile)
build(:ruby_version)
build(:configru)
unless options[:skip_git]
build(:gitignore)
build(:gitattributes)
end
build(:gemfile)
build(:version_control)
end
|
#create_storage_files ⇒ Object
420
421
422
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 420
def create_storage_files
build(:storage) unless skip_active_storage?
end
|
#create_system_test_files ⇒ Object
416
417
418
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 416
def create_system_test_files
build(:system_test) if depends_on_system_test?
end
|
#create_test_files ⇒ Object
412
413
414
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 412
def create_test_files
build(:test) unless options[:skip_test]
end
|
#create_tmp_files ⇒ Object
404
405
406
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 404
def create_tmp_files
build(:tmp)
end
|
#create_vendor_files ⇒ Object
408
409
410
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 408
def create_vendor_files
build(:vendor)
end
|
#delete_action_cable_files_skipping_action_cable ⇒ Object
494
495
496
497
498
499
500
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 494
def delete_action_cable_files_skipping_action_cable
if options[:skip_action_cable]
remove_dir "app/javascript/channels"
remove_dir "app/channels"
remove_dir "test/channels"
end
end
|
#delete_action_mailer_files_skipping_action_mailer ⇒ Object
485
486
487
488
489
490
491
492
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 485
def delete_action_mailer_files_skipping_action_mailer
if options[:skip_action_mailer]
remove_file "app/views/layouts/mailer.html.erb"
remove_file "app/views/layouts/mailer.text.erb"
remove_dir "app/mailers"
remove_dir "test/mailers"
end
end
|
#delete_active_job_folder_if_skipping_active_job ⇒ Object
479
480
481
482
483
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 479
def delete_active_job_folder_if_skipping_active_job
if options[:skip_active_job]
remove_dir "app/jobs"
end
end
|
#delete_api_initializers ⇒ Object
509
510
511
512
513
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 509
def delete_api_initializers
unless options[:api]
remove_file "config/initializers/cors.rb"
end
end
|
#delete_app_assets_if_api_option ⇒ Object
424
425
426
427
428
429
430
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 424
def delete_app_assets_if_api_option
if options[:api]
remove_dir "app/assets"
remove_dir "lib/assets"
remove_dir "tmp/cache/assets"
end
end
|
#delete_app_helpers_if_api_option ⇒ Object
432
433
434
435
436
437
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 432
def delete_app_helpers_if_api_option
if options[:api]
remove_dir "app/helpers"
remove_dir "test/helpers"
end
end
|
#delete_app_views_if_api_option ⇒ Object
439
440
441
442
443
444
445
446
447
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 439
def delete_app_views_if_api_option
if options[:api]
if options[:skip_action_mailer]
remove_dir "app/views"
else
remove_file "app/views/layouts/application.html.erb"
end
end
end
|
#delete_application_record_skipping_active_record ⇒ Object
473
474
475
476
477
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 473
def delete_application_record_skipping_active_record
if options[:skip_active_record]
remove_file "app/models/application_record.rb"
end
end
|
#delete_assets_initializer_skipping_sprockets_and_propshaft ⇒ Object
460
461
462
463
464
465
466
467
468
469
470
471
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 460
def delete_assets_initializer_skipping_sprockets_and_propshaft
if skip_sprockets? && skip_propshaft?
remove_file "config/initializers/assets.rb"
end
if skip_sprockets?
remove_file "app/assets/config/manifest.js"
remove_dir "app/assets/config"
remove_file "app/assets/stylesheets/application.css"
create_file "app/assets/stylesheets/application.css", "/* Application styles */\n" unless options[:api]
end
end
|
#delete_new_framework_defaults ⇒ Object
515
516
517
518
519
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 515
def delete_new_framework_defaults
unless options[:update]
remove_file "config/initializers/new_framework_defaults_7_0.rb"
end
end
|
#delete_non_api_initializers_if_api_option ⇒ Object
502
503
504
505
506
507
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 502
def delete_non_api_initializers_if_api_option
if options[:api]
remove_file "config/initializers/content_security_policy.rb"
remove_file "config/initializers/permissions_policy.rb"
end
end
|
#delete_public_files_if_api_option ⇒ Object
449
450
451
452
453
454
455
456
457
458
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 449
def delete_public_files_if_api_option
if options[:api]
remove_file "public/404.html"
remove_file "public/422.html"
remove_file "public/500.html"
remove_file "public/apple-touch-icon-precomposed.png"
remove_file "public/apple-touch-icon.png"
remove_file "public/favicon.ico"
end
end
|
#display_upgrade_guide_info ⇒ Object
373
374
375
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 373
def display_upgrade_guide_info
say "\nAfter this, check Rails upgrade guide at https://guides.rubyonrails.org/upgrading_ruby_on_rails.html for more details about upgrading your app."
end
|
#finish_template ⇒ Object
521
522
523
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 521
def finish_template
build(:leftovers)
end
|
#run_after_bundle_callbacks ⇒ Object
531
532
533
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 531
def run_after_bundle_callbacks
@after_bundle_callbacks.each(&:call)
end
|
#update_active_storage ⇒ Object
349
350
351
352
353
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 349
def update_active_storage
unless skip_active_storage?
rails_command "active_storage:update", inline: true
end
end
|
#update_bin_files ⇒ Object
339
340
341
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 339
def update_bin_files
build(:bin_when_updating)
end
|
#update_config_files ⇒ Object
360
361
362
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 360
def update_config_files
build(:config_when_updating)
end
|
#update_db_schema ⇒ Object
344
345
346
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 344
def update_db_schema
build(:db_when_updating)
end
|