Class: Rails::Generators::AppGenerator
- Inherits:
-
AppBase
- Object
- Thor::Group
- Base
- AppBase
- Rails::Generators::AppGenerator
show all
- Defined in:
- lib/rails/generators/rails/app/app_generator.rb,
lib/rails/commands/application/application_command.rb
Overview
Constant Summary
collapse
- WEBPACKS =
%w( react vue angular elm stimulus )
Constants inherited
from AppBase
Rails::Generators::AppBase::DATABASES, Rails::Generators::AppBase::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 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, #after_bundle, #capify!, #environment, #gem, #gem_group, #generate, #git, #initializer, #lib, #rails_command, #rake, #rakefile, #readme, #route, #vendor
Constructor Details
Returns a new instance of AppGenerator.
273
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 273
def initialize(*args)
super
if !options[:skip_active_record] && !DATABASES.include?(options[:database])
raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}."
end
if options[:api]
self.options = options.merge(skip_sprockets: true, skip_javascript: true, skip_yarn: true).freeze
end
end
|
Class Method Details
.banner ⇒ Object
486
487
488
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 486
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
340
341
342
343
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 340
def create_active_record_files
return if options[:skip_active_record]
build(:database_yml)
end
|
#create_app_files ⇒ Object
301
302
303
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 301
def create_app_files
build(:app)
end
|
#create_bin_files ⇒ Object
305
306
307
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 305
def create_bin_files
build(:bin)
end
|
#create_boot_file ⇒ Object
336
337
338
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 336
def create_boot_file
template "config/boot.rb"
end
|
#create_config_files ⇒ Object
314
315
316
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 314
def create_config_files
build(:config)
end
|
#create_credentials ⇒ Object
327
328
329
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 327
def create_credentials
build(:credentials)
end
|
#create_db_files ⇒ Object
345
346
347
348
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 345
def create_db_files
return if options[:skip_active_record]
build(:db)
end
|
#create_lib_files ⇒ Object
350
351
352
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 350
def create_lib_files
build(:lib)
end
|
#create_log_files ⇒ Object
354
355
356
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 354
def create_log_files
build(:log)
end
|
#create_master_key ⇒ Object
323
324
325
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 323
def create_master_key
build(:master_key)
end
|
#create_public_files ⇒ Object
358
359
360
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 358
def create_public_files
build(:public_directory)
end
|
#create_root_files ⇒ Object
290
291
292
293
294
295
296
297
298
299
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 290
def create_root_files
build(:readme)
build(:rakefile)
build(:ruby_version)
build(:configru)
build(:gitignore) unless options[:skip_git]
build(:gemfile) unless options[:skip_gemfile]
build(:version_control)
build(:package_json) unless options[:skip_yarn]
end
|
#create_storage_files ⇒ Object
378
379
380
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 378
def create_storage_files
build(:storage) unless skip_active_storage?
end
|
#create_system_test_files ⇒ Object
374
375
376
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 374
def create_system_test_files
build(:system_test) if depends_on_system_test?
end
|
#create_test_files ⇒ Object
370
371
372
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 370
def create_test_files
build(:test) unless options[:skip_test]
end
|
#create_tmp_files ⇒ Object
362
363
364
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 362
def create_tmp_files
build(:tmp)
end
|
#create_vendor_files ⇒ Object
366
367
368
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 366
def create_vendor_files
build(:vendor)
end
|
#delete_action_cable_files_skipping_action_cable ⇒ Object
445
446
447
448
449
450
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 445
def delete_action_cable_files_skipping_action_cable
if options[:skip_action_cable]
remove_file "app/assets/javascripts/cable.js"
remove_dir "app/channels"
end
end
|
#delete_action_mailer_files_skipping_action_mailer ⇒ Object
436
437
438
439
440
441
442
443
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 436
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_api_initializers ⇒ Object
459
460
461
462
463
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 459
def delete_api_initializers
unless options[:api]
remove_file "config/initializers/cors.rb"
end
end
|
#delete_app_assets_if_api_option ⇒ Object
382
383
384
385
386
387
388
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 382
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
390
391
392
393
394
395
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 390
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
397
398
399
400
401
402
403
404
405
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 397
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
430
431
432
433
434
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 430
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 ⇒ Object
424
425
426
427
428
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 424
def delete_assets_initializer_skipping_sprockets
if options[:skip_sprockets]
remove_file "config/initializers/assets.rb"
end
end
|
#delete_bin_yarn_if_skip_yarn_option ⇒ Object
471
472
473
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 471
def delete_bin_yarn_if_skip_yarn_option
remove_file "bin/yarn" if options[:skip_yarn]
end
|
#delete_js_folder_skipping_javascript ⇒ Object
418
419
420
421
422
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 418
def delete_js_folder_skipping_javascript
if options[:skip_javascript]
remove_dir "app/assets/javascripts"
end
end
|
#delete_new_framework_defaults ⇒ Object
465
466
467
468
469
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 465
def delete_new_framework_defaults
unless options[:update]
remove_file "config/initializers/new_framework_defaults_5_2.rb"
end
end
|
#delete_non_api_initializers_if_api_option ⇒ Object
452
453
454
455
456
457
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 452
def delete_non_api_initializers_if_api_option
if options[:api]
remove_file "config/initializers/cookies_serializer.rb"
remove_file "config/initializers/content_security_policy.rb"
end
end
|
#delete_public_files_if_api_option ⇒ Object
407
408
409
410
411
412
413
414
415
416
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 407
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
331
332
333
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 331
def display_upgrade_guide_info
say "\nAfter this, check Rails upgrade guide at http://guides.rubyonrails.org/upgrading_ruby_on_rails.html for more details about upgrading your app."
end
|
#finish_template ⇒ Object
475
476
477
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 475
def finish_template
build(:leftovers)
end
|
#run_after_bundle_callbacks ⇒ Object
482
483
484
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 482
def run_after_bundle_callbacks
@after_bundle_callbacks.each(&:call)
end
|
#update_bin_files ⇒ Object
309
310
311
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 309
def update_bin_files
build(:bin_when_updating)
end
|
#update_config_files ⇒ Object
318
319
320
|
# File 'lib/rails/generators/rails/app/app_generator.rb', line 318
def update_config_files
build(:config_when_updating)
end
|