Class: Rails::Generators::AppGenerator

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

Overview

:nodoc:

Constant Summary

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.


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/rails/generators/rails/app/app_generator.rb', line 185

def initialize(*args)
  super

  unless app_path
    raise Error, "Application name should be provided in arguments. For details run: rails --help"
  end

  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 to be skipped when generating API only apps.
  # Can't modify options hash as it's frozen by default.
  self.options = options.merge(skip_sprockets: true, skip_javascript: true).freeze if options[:api]
end

Class Method Details

.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.rb', line 9

def self.exit_on_failure?
  true
end

Instance Method Details

#create_active_record_filesObject


238
239
240
241
# File 'lib/rails/generators/rails/app/app_generator.rb', line 238

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

#create_app_filesObject


212
213
214
# File 'lib/rails/generators/rails/app/app_generator.rb', line 212

def create_app_files
  build(:app)
end

#create_bin_filesObject


216
217
218
# File 'lib/rails/generators/rails/app/app_generator.rb', line 216

def create_bin_files
  build(:bin)
end

#create_boot_fileObject


234
235
236
# File 'lib/rails/generators/rails/app/app_generator.rb', line 234

def create_boot_file
  template "config/boot.rb"
end

#create_config_filesObject


220
221
222
# File 'lib/rails/generators/rails/app/app_generator.rb', line 220

def create_config_files
  build(:config)
end

#create_db_filesObject


243
244
245
# File 'lib/rails/generators/rails/app/app_generator.rb', line 243

def create_db_files
  build(:db)
end

#create_lib_filesObject


247
248
249
# File 'lib/rails/generators/rails/app/app_generator.rb', line 247

def create_lib_files
  build(:lib)
end

#create_log_filesObject


251
252
253
# File 'lib/rails/generators/rails/app/app_generator.rb', line 251

def create_log_files
  build(:log)
end

#create_public_filesObject


255
256
257
# File 'lib/rails/generators/rails/app/app_generator.rb', line 255

def create_public_files
  build(:public_directory)
end

#create_root_filesObject


204
205
206
207
208
209
210
# File 'lib/rails/generators/rails/app/app_generator.rb', line 204

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

#create_test_filesObject


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

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

#create_tmp_filesObject


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

def create_tmp_files
  build(:tmp)
end

#create_vendor_filesObject


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

def create_vendor_files
  build(:vendor)
end

#delete_action_cable_files_skipping_action_cableObject


332
333
334
335
336
337
338
# File 'lib/rails/generators/rails/app/app_generator.rb', line 332

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


322
323
324
325
326
327
328
329
330
# File 'lib/rails/generators/rails/app/app_generator.rb', line 322

def delete_action_mailer_files_skipping_action_mailer
  if options[:skip_action_mailer]
    remove_file "app/mailers/application_mailer.rb"
    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


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

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

#delete_app_assets_if_api_optionObject


271
272
273
274
275
276
277
278
# File 'lib/rails/generators/rails/app/app_generator.rb', line 271

def delete_app_assets_if_api_option
  if options[:api]
    remove_dir 'app/assets'
    remove_dir 'lib/assets'
    remove_dir 'tmp/cache/assets'
    remove_dir 'vendor/assets'
  end
end

#delete_app_helpers_if_api_optionObject


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

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


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

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


316
317
318
319
320
# File 'lib/rails/generators/rails/app/app_generator.rb', line 316

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


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

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

#delete_js_folder_skipping_javascriptObject


304
305
306
307
308
# File 'lib/rails/generators/rails/app/app_generator.rb', line 304

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

#delete_non_api_initializers_if_api_optionObject


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

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

#delete_public_files_if_api_optionObject


293
294
295
296
297
298
299
300
301
302
# File 'lib/rails/generators/rails/app/app_generator.rb', line 293

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


229
230
231
# File 'lib/rails/generators/rails/app/app_generator.rb', line 229

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


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

def finish_template
  build(:leftovers)
end

#run_after_bundle_callbacksObject


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

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

#update_config_filesObject


224
225
226
# File 'lib/rails/generators/rails/app/app_generator.rb', line 224

def update_config_files
  build(:config_when_updating)
end