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
Constant Summary
collapse
- OPTION_IMPLICATIONS =
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_brakeman,
:skip_bundler_audit,
:skip_ci,
:skip_dev_gems,
:skip_docker,
:skip_hotwire,
:skip_javascript,
:skip_jbuilder,
:skip_kamal,
:skip_rubocop,
:skip_solid,
:skip_system_test,
:skip_thruster
],
api: [
:skip_asset_pipeline,
:skip_javascript,
],
) do |option, implications, more_implications|
implications + more_implications
end
- META_OPTIONS =
[:minimal]
Constants inherited
from AppBase
Rails::Generators::AppBase::BUN_VERSION, Rails::Generators::AppBase::CSS_OPTIONS, Rails::Generators::AppBase::JAVASCRIPT_OPTIONS, Rails::Generators::AppBase::NODE_LTS_VERSION
Constants included
from AppName
Rails::Generators::AppName::RESERVED_NAMES
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
#bundle_command
Methods inherited from Base
add_shebang_option!, base_name, base_root, class_option, default_aliases_for_option, default_for_option, default_generator_root, default_source_root, default_value_for_option, desc, generator_name, hide!, hook_for, hooks, inherited, namespace, prepare_for_invocation, remove_hook_for, source_root, usage_path
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.
359
360
361
362
363
364
365
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 359
def initialize(*args)
super
imply_options(OPTION_IMPLICATIONS, meta_options: META_OPTIONS)
@after_bundle_callbacks = []
end
|
Class Method Details
.apply_rails_template(template, destination) ⇒ Object
351
352
353
354
355
356
357
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 351
def self.apply_rails_template(template, destination) generator = new([destination], { template: template }, { destination_root: destination })
generator.set_default_accessors!
generator.apply_rails_template
generator.run_bundle
generator.run_after_bundle_callbacks
end
|
604
605
606
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 604
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 'railties/lib/rails/commands/application/application_command.rb', line 11
def self.exit_on_failure?
true
end
|
Instance Method Details
#create_active_record_files ⇒ Object
446
447
448
449
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 446
def create_active_record_files
return if options[:skip_active_record]
build(:database_yml)
end
|
#create_app_files ⇒ Object
388
389
390
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 388
def create_app_files
build(:app)
end
|
#create_bin_files ⇒ Object
392
393
394
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 392
def create_bin_files
build(:bin)
end
|
#create_boot_file ⇒ Object
442
443
444
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 442
def create_boot_file
template "config/boot.rb"
end
|
#create_cifiles ⇒ Object
418
419
420
421
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 418
def create_cifiles
return if skip_ci?
build(:cifiles)
end
|
#create_config_files ⇒ Object
423
424
425
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 423
def create_config_files
build(:config)
end
|
#create_creds ⇒ Object
436
437
438
439
440
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 436
def create_creds
build(:env)
build(:credentials)
build(:credentials_diff_enroll)
end
|
#create_db_files ⇒ Object
451
452
453
454
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 451
def create_db_files
return if options[:skip_active_record]
build(:db)
end
|
#create_devcontainer_files ⇒ Object
493
494
495
496
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 493
def create_devcontainer_files
return if skip_devcontainer? || options[:dummy_app]
build(:devcontainer)
end
|
#create_dockerfiles ⇒ Object
408
409
410
411
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 408
def create_dockerfiles
return if options[:skip_docker] || options[:dummy_app]
build(:dockerfiles)
end
|
#create_lib_files ⇒ Object
456
457
458
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 456
def create_lib_files
build(:lib)
end
|
#create_log_files ⇒ Object
460
461
462
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 460
def create_log_files
build(:log)
end
|
#create_master_key ⇒ Object
432
433
434
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 432
def create_master_key
build(:master_key)
end
|
#create_public_files ⇒ Object
464
465
466
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 464
def create_public_files
build(:public_directory)
end
|
#create_root_files ⇒ Object
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 372
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_rubocop_file ⇒ Object
413
414
415
416
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 413
def create_rubocop_file
return if skip_rubocop?
build(:rubocop)
end
|
#create_script_folder ⇒ Object
468
469
470
471
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 468
def create_script_folder
return if options[:dummy_app]
build(:script)
end
|
#create_storage_files ⇒ Object
489
490
491
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 489
def create_storage_files
build(:storage) unless skip_storage?
end
|
#create_system_test_files ⇒ Object
485
486
487
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 485
def create_system_test_files
build(:system_test)
end
|
#create_test_files ⇒ Object
481
482
483
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 481
def create_test_files
build(:test) unless options[:skip_test]
end
|
#create_tmp_files ⇒ Object
473
474
475
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 473
def create_tmp_files
build(:tmp)
end
|
#create_vendor_files ⇒ Object
477
478
479
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 477
def create_vendor_files
build(:vendor)
end
|
#delete_action_cable_files_skipping_action_cable ⇒ Object
563
564
565
566
567
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 563
def delete_action_cable_files_skipping_action_cable
if options[:skip_action_cable]
remove_dir "app/javascript/channels"
end
end
|
#delete_action_mailer_files_skipping_action_mailer ⇒ Object
554
555
556
557
558
559
560
561
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 554
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
548
549
550
551
552
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 548
def delete_active_job_folder_if_skipping_active_job
if options[:skip_active_job]
remove_dir "app/jobs"
end
end
|
#delete_api_initializers ⇒ Object
575
576
577
578
579
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 575
def delete_api_initializers
unless options[:api]
remove_file "config/initializers/cors.rb"
end
end
|
#delete_app_assets_if_api_option ⇒ Object
498
499
500
501
502
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 498
def delete_app_assets_if_api_option
if options[:api]
remove_dir "app/assets"
end
end
|
#delete_app_helpers_if_api_option ⇒ Object
504
505
506
507
508
509
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 504
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
511
512
513
514
515
516
517
518
519
520
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 511
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"
remove_dir "app/views/pwa"
end
end
end
|
#delete_application_record_skipping_active_record ⇒ Object
542
543
544
545
546
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 542
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_asset_pipeline ⇒ Object
534
535
536
537
538
539
540
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 534
def delete_assets_initializer_skipping_asset_pipeline
if skip_asset_pipeline?
remove_file "config/initializers/assets.rb"
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
581
582
583
584
585
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 581
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_option ⇒ Object
569
570
571
572
573
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 569
def delete_non_api_initializers_if_api_option
if options[:api]
remove_file "config/initializers/content_security_policy.rb"
end
end
|
#delete_public_files_if_api_option ⇒ Object
522
523
524
525
526
527
528
529
530
531
532
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 522
def delete_public_files_if_api_option
if options[:api]
remove_file "public/400.html"
remove_file "public/404.html"
remove_file "public/406-unsupported-browser.html"
remove_file "public/422.html"
remove_file "public/500.html"
remove_file "public/icon.png"
remove_file "public/icon.svg"
end
end
|
#finish_template ⇒ Object
587
588
589
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 587
def finish_template
build(:leftovers)
end
|
#run_after_bundle_callbacks ⇒ Object
600
601
602
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 600
def run_after_bundle_callbacks
@after_bundle_callbacks.each(&:call)
end
|
#update_active_storage ⇒ Object
401
402
403
404
405
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 401
def update_active_storage
unless skip_active_storage?
rails_command "active_storage:update", inline: true
end
end
|
#update_bin_files ⇒ Object
396
397
398
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 396
def update_bin_files
build(:bin_when_updating)
end
|
#update_config_files ⇒ Object
427
428
429
|
# File 'railties/lib/rails/generators/rails/app/app_generator.rb', line 427
def update_config_files
build(:config_when_updating)
end
|