Class: Rails::Generators::AppGenerator

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

Overview

:nodoc:

Constant Summary collapse

WEBPACKS =
%w( react vue angular )

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

#initialize(*args) ⇒ AppGenerator

Returns a new instance of AppGenerator.



232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/rails/generators/rails/app/app_generator.rb', line 232

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

  # Force sprockets and yarn to be skipped when generating API only apps.
  # Can't modify options hash as it's frozen by default.
  if options[:api]
    self.options = options.merge(skip_sprockets: true, skip_javascript: true, skip_yarn: true).freeze
  end
end

Class Method Details



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

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)


9
10
11
# File 'lib/rails/commands/application/application_command.rb', line 9

def self.exit_on_failure?
  true
end

Instance Method Details

#create_active_record_filesObject



289
290
291
292
# File 'lib/rails/generators/rails/app/app_generator.rb', line 289

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

#create_app_filesObject



258
259
260
# File 'lib/rails/generators/rails/app/app_generator.rb', line 258

def create_app_files
  build(:app)
end

#create_bin_filesObject



262
263
264
# File 'lib/rails/generators/rails/app/app_generator.rb', line 262

def create_bin_files
  build(:bin)
end

#create_boot_fileObject



285
286
287
# File 'lib/rails/generators/rails/app/app_generator.rb', line 285

def create_boot_file
  template "config/boot.rb"
end

#create_config_filesObject



271
272
273
# File 'lib/rails/generators/rails/app/app_generator.rb', line 271

def create_config_files
  build(:config)
end

#create_db_filesObject



294
295
296
297
# File 'lib/rails/generators/rails/app/app_generator.rb', line 294

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

#create_lib_filesObject



299
300
301
# File 'lib/rails/generators/rails/app/app_generator.rb', line 299

def create_lib_files
  build(:lib)
end

#create_log_filesObject



303
304
305
# File 'lib/rails/generators/rails/app/app_generator.rb', line 303

def create_log_files
  build(:log)
end

#create_public_filesObject



307
308
309
# File 'lib/rails/generators/rails/app/app_generator.rb', line 307

def create_public_files
  build(:public_directory)
end

#create_root_filesObject



249
250
251
252
253
254
255
256
# File 'lib/rails/generators/rails/app/app_generator.rb', line 249

def create_root_files
  build(:readme)
  build(:rakefile)
  build(:configru)
  build(:gitignore)   unless options[:skip_git]
  build(:gemfile)     unless options[:skip_gemfile]
  build(:version_control)
end

#create_system_test_filesObject



315
316
317
# File 'lib/rails/generators/rails/app/app_generator.rb', line 315

def create_system_test_files
  build(:system_test) if depends_on_system_test?
end

#create_test_filesObject



311
312
313
# File 'lib/rails/generators/rails/app/app_generator.rb', line 311

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

#create_tmp_filesObject



319
320
321
# File 'lib/rails/generators/rails/app/app_generator.rb', line 319

def create_tmp_files
  build(:tmp)
end

#create_vendor_filesObject



323
324
325
# File 'lib/rails/generators/rails/app/app_generator.rb', line 323

def create_vendor_files
  build(:vendor)
end

#delete_action_cable_files_skipping_action_cableObject



386
387
388
389
390
391
392
# File 'lib/rails/generators/rails/app/app_generator.rb', line 386

def delete_action_cable_files_skipping_action_cable
  if options[:skip_action_cable]
    remove_file "config/cable.yml"
    remove_file "app/assets/javascripts/cable.js"
    remove_dir "app/channels"
  end
end

#delete_action_mailer_files_skipping_action_mailerObject



377
378
379
380
381
382
383
384
# File 'lib/rails/generators/rails/app/app_generator.rb', line 377

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_initializersObject



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

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

#delete_app_assets_if_api_optionObject



327
328
329
330
331
332
333
# File 'lib/rails/generators/rails/app/app_generator.rb', line 327

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



335
336
337
338
339
340
# File 'lib/rails/generators/rails/app/app_generator.rb', line 335

def delete_app_helpers_if_api_option
  if options[:api]
    remove_dir "app/helpers"
    remove_dir "test/helpers"
  end
end

#delete_application_layout_file_if_api_optionObject



342
343
344
345
346
# File 'lib/rails/generators/rails/app/app_generator.rb', line 342

def delete_application_layout_file_if_api_option
  if options[:api]
    remove_file "app/views/layouts/application.html.erb"
  end
end

#delete_application_record_skipping_active_recordObject



371
372
373
374
375
# File 'lib/rails/generators/rails/app/app_generator.rb', line 371

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_sprocketsObject



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

def delete_assets_initializer_skipping_sprockets
  if options[:skip_sprockets]
    remove_file "config/initializers/assets.rb"
  end
end

#delete_bin_yarn_if_skip_yarn_optionObject



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

def delete_bin_yarn_if_skip_yarn_option
  remove_file "bin/yarn" if options[:skip_yarn]
end

#delete_js_folder_skipping_javascriptObject



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

def delete_js_folder_skipping_javascript
  if options[:skip_javascript]
    remove_dir "app/assets/javascripts"
  end
end

#delete_new_framework_defaultsObject



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

def delete_new_framework_defaults
  unless options[:update]
    remove_file "config/initializers/new_framework_defaults_5_1.rb"
  end
end

#delete_non_api_initializers_if_api_optionObject



394
395
396
397
398
# File 'lib/rails/generators/rails/app/app_generator.rb', line 394

def delete_non_api_initializers_if_api_option
  if options[:api]
    remove_file "config/initializers/cookies_serializer.rb"
  end
end

#delete_public_files_if_api_optionObject



348
349
350
351
352
353
354
355
356
357
# File 'lib/rails/generators/rails/app/app_generator.rb', line 348

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



280
281
282
# File 'lib/rails/generators/rails/app/app_generator.rb', line 280

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_templateObject



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

def finish_template
  build(:leftovers)
end

#run_after_bundle_callbacksObject



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

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

#update_bin_filesObject



266
267
268
# File 'lib/rails/generators/rails/app/app_generator.rb', line 266

def update_bin_files
  build(:bin_when_updating)
end

#update_config_filesObject



275
276
277
# File 'lib/rails/generators/rails/app/app_generator.rb', line 275

def update_config_files
  build(:config_when_updating)
end