Class Rails::Generator::Commands::Destroy
In: vendor/rails/railties/lib/rails_generator/commands.rb
Parent: RewindBase

Undo the actions performed by a generator. Rewind the action manifest and attempt to completely erase the results of each action.

Methods

Public Instance methods

[Source]

     # File vendor/rails/railties/lib/rails_generator/commands.rb, line 500
500:         def complex_template(*args)
501:           # nothing should be done here
502:         end

Remove each directory in the given path from right to left. Remove each subdirectory if it exists and is a directory.

[Source]

     # File vendor/rails/railties/lib/rails_generator/commands.rb, line 464
464:         def directory(relative_path)
465:           parts = relative_path.split('/')
466:           until parts.empty?
467:             partial = File.join(parts)
468:             path = destination_path(partial)
469:             if File.exist?(path)
470:               if Dir[File.join(path, '*')].empty?
471:                 logger.rmdir partial
472:                 unless options[:pretend]
473:                   if options[:svn]
474:                     # If the directory has been marked to be added
475:                     # but has not yet been checked in, revert and delete
476:                     if options[:svn][relative_path]
477:                       system("svn revert #{path}")
478:                       FileUtils.rmdir(path)
479:                     else
480:                     # If the directory is not in the status list, it
481:                     # has no modifications so we can simply remove it
482:                       system("svn rm #{path}")
483:                     end
484:                   # I don't think git needs to remove directories?..
485:                   # or maybe they have special consideration...
486:                   else
487:                     FileUtils.rmdir(path)
488:                   end
489:                 end
490:               else
491:                 logger.notempty partial
492:               end
493:             else
494:               logger.missing partial
495:             end
496:             parts.pop
497:           end
498:         end

Remove a file if it exists and is a file.

[Source]

     # File vendor/rails/railties/lib/rails_generator/commands.rb, line 419
419:         def file(relative_source, relative_destination, file_options = {})
420:           destination = destination_path(relative_destination)
421:           if File.exist?(destination)
422:             logger.rm relative_destination
423:             unless options[:pretend]
424:               if options[:svn]
425:                 # If the file has been marked to be added
426:                 # but has not yet been checked in, revert and delete
427:                 if options[:svn][relative_destination]
428:                   system("svn revert #{destination}")
429:                   FileUtils.rm(destination)
430:                 else
431:                 # If the directory is not in the status list, it
432:                 # has no modifications so we can simply remove it
433:                   system("svn rm #{destination}")
434:                 end
435:               elsif options[:git]
436:                 if options[:git][:new][relative_destination]
437:                   # file has been added, but not committed
438:                   system("git reset HEAD #{relative_destination}")
439:                   FileUtils.rm(destination)
440:                 elsif options[:git][:modified][relative_destination]
441:                   # file is committed and modified
442:                   system("git rm -f #{relative_destination}")
443:                 else
444:                   # If the directory is not in the status list, it
445:                   # has no modifications so we can simply remove it
446:                   system("git rm #{relative_destination}")
447:                 end
448:               else
449:                 FileUtils.rm(destination)
450:               end
451:             end
452:           else
453:             logger.missing relative_destination
454:             return
455:           end
456:         end

When deleting a migration, it knows to delete every file named "[0-9]*_#{file_name}".

[Source]

     # File vendor/rails/railties/lib/rails_generator/commands.rb, line 505
505:         def migration_template(relative_source, relative_destination, template_options = {})
506:           migration_directory relative_destination
507: 
508:           migration_file_name = template_options[:migration_file_name] || file_name
509:           unless migration_exists?(migration_file_name)
510:             puts "There is no migration named #{migration_file_name}"
511:             return
512:           end
513: 
514: 
515:           existing_migrations(migration_file_name).each do |file_path|
516:             file(relative_source, file_path, template_options)
517:           end
518:         end

[Source]

     # File vendor/rails/railties/lib/rails_generator/commands.rb, line 520
520:         def route_resources(*resources)
521:           resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
522:           look_for = "\n  map.resources #{resource_list}\n"
523:           logger.route "map.resources #{resource_list}"
524:           gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
525:         end
template(relative_source, relative_destination, file_options = {})

Alias for file

[Validate]