Class: Rails::Generators::AppGenerator

Inherits:
AppBase show all
Defined in:
railties/lib/rails/commands/application/application_command.rb,
railties/lib/rails/generators/rails/app/app_generator.rb

Overview

:nodoc:

Constant Summary collapse

OPTION_IMPLICATIONS =

:nodoc:

AppBase::OPTION_IMPLICATIONS.merge(
  skip_git: [:skip_decrypted_diffs],
  minimal: [
    :skip_action_cable,
    :skip_action_mailbox,
    :skip_action_mailer,
    :skip_action_text,
    :skip_active_job,
    :skip_active_storage,
    :skip_bootsnap,
    :skip_dev_gems,
    :skip_hotwire,
    :skip_javascript,
    :skip_jbuilder,
    :skip_system_test,
  ],
  api: [
    :skip_asset_pipeline,
    :skip_javascript,
  ],
) do |option, implications, more_implications|
  implications + more_implications
end
META_OPTIONS =

:nodoc:

[:minimal]

Constants inherited from AppBase

Rails::Generators::AppBase::NODE_LTS_VERSION

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, edge_branch, 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

#initialize(*args) ⇒ AppGenerator

Returns a new instance of AppGenerator.



312
313
314
315
316
317
318
319
320
321
322
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 312

def initialize(*args)
  super

  imply_options(OPTION_IMPLICATIONS, meta_options: META_OPTIONS)

  if !options[:skip_active_record] && !DATABASES.include?(options[:database])
    raise Error, "Invalid value for --database option. Supported preconfigurations are: #{DATABASES.join(", ")}."
  end

  @after_bundle_callbacks = []
end

Class Method Details



550
551
552
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 550

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

Returns:

  • (Boolean)


11
12
13
# File 'railties/lib/rails/commands/application/application_command.rb', line 11

def self.exit_on_failure?
  true
end

Instance Method Details

#create_active_record_filesObject



397
398
399
400
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 397

def create_active_record_files
  return if options[:skip_active_record]
  build(:database_yml)
end

#create_app_filesObject



345
346
347
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 345

def create_app_files
  build(:app)
end

#create_bin_filesObject



349
350
351
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 349

def create_bin_files
  build(:bin)
end

#create_boot_fileObject



393
394
395
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 393

def create_boot_file
  template "config/boot.rb"
end

#create_config_filesObject



370
371
372
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 370

def create_config_files
  build(:config)
end

#create_credentialsObject



383
384
385
386
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 383

def create_credentials
  build(:credentials)
  build(:credentials_diff_enroll)
end

#create_db_filesObject



402
403
404
405
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 402

def create_db_files
  return if options[:skip_active_record]
  build(:db)
end

#create_dockerfilesObject



365
366
367
368
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 365

def create_dockerfiles
  return if options[:skip_docker] || options[:dummy_app]
  build(:dockerfiles)
end

#create_lib_filesObject



407
408
409
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 407

def create_lib_files
  build(:lib)
end

#create_log_filesObject



411
412
413
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 411

def create_log_files
  build(:log)
end

#create_master_keyObject



379
380
381
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 379

def create_master_key
  build(:master_key)
end

#create_public_filesObject



415
416
417
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 415

def create_public_files
  build(:public_directory)
end

#create_root_filesObject



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 329

def create_root_files
  build(:readme)
  build(:rakefile)
  build(:node_version) if using_node?
  build(:ruby_version)
  build(:configru)

  unless options[:skip_git]
    build(:gitignore)
    build(:gitattributes)
  end

  build(:gemfile)
  build(:version_control)
end

#create_storage_filesObject



435
436
437
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 435

def create_storage_files
  build(:storage)
end

#create_system_test_filesObject



431
432
433
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 431

def create_system_test_files
  build(:system_test) if depends_on_system_test?
end

#create_test_filesObject



427
428
429
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 427

def create_test_files
  build(:test) unless options[:skip_test]
end

#create_tmp_filesObject



419
420
421
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 419

def create_tmp_files
  build(:tmp)
end

#create_vendor_filesObject



423
424
425
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 423

def create_vendor_files
  build(:vendor)
end

#delete_action_cable_files_skipping_action_cableObject



509
510
511
512
513
514
515
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 509

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_mailerObject



500
501
502
503
504
505
506
507
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 500

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_jobObject



494
495
496
497
498
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 494

def delete_active_job_folder_if_skipping_active_job
  if options[:skip_active_job]
    remove_dir "app/jobs"
  end
end

#delete_api_initializersObject



524
525
526
527
528
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 524

def delete_api_initializers
  unless options[:api]
    remove_file "config/initializers/cors.rb"
  end
end

#delete_app_assets_if_api_optionObject



439
440
441
442
443
444
445
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 439

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_optionObject



447
448
449
450
451
452
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 447

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_optionObject



454
455
456
457
458
459
460
461
462
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 454

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_recordObject



488
489
490
491
492
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 488

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_propshaftObject



475
476
477
478
479
480
481
482
483
484
485
486
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 475

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_defaultsObject



530
531
532
533
534
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 530

def delete_new_framework_defaults
  unless options[:update]
    remove_file "config/initializers/new_framework_defaults_#{Rails::VERSION::MAJOR}_#{Rails::VERSION::MINOR}.rb"
  end
end

#delete_non_api_initializers_if_api_optionObject



517
518
519
520
521
522
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 517

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_optionObject



464
465
466
467
468
469
470
471
472
473
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 464

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_infoObject



388
389
390
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 388

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_templateObject



536
537
538
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 536

def finish_template
  build(:leftovers)
end

#run_after_bundle_callbacksObject



546
547
548
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 546

def run_after_bundle_callbacks
  @after_bundle_callbacks.each(&:call)
end

#update_active_storageObject



358
359
360
361
362
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 358

def update_active_storage
  unless skip_active_storage?
    rails_command "active_storage:update", inline: true
  end
end

#update_bin_filesObject



353
354
355
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 353

def update_bin_files
  build(:bin_when_updating)
end

#update_config_filesObject



374
375
376
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 374

def update_config_files
  build(:config_when_updating)
end