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 525
525:         def complex_template(*args)
526:           # nothing should be done here
527:         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 489
489:         def directory(relative_path)
490:           parts = relative_path.split('/')
491:           until parts.empty?
492:             partial = File.join(parts)
493:             path = destination_path(partial)
494:             if File.exist?(path)
495:               if Dir[File.join(path, '*')].empty?
496:                 logger.rmdir partial
497:                 unless options[:pretend]
498:                   if options[:svn]
499:                     # If the directory has been marked to be added
500:                     # but has not yet been checked in, revert and delete
501:                     if options[:svn][relative_path]
502:                       system("svn revert #{path}")
503:                       FileUtils.rmdir(path)
504:                     else
505:                     # If the directory is not in the status list, it
506:                     # has no modifications so we can simply remove it
507:                       system("svn rm #{path}")
508:                     end
509:                   # I don't think git needs to remove directories?..
510:                   # or maybe they have special consideration...
511:                   else
512:                     FileUtils.rmdir(path)
513:                   end
514:                 end
515:               else
516:                 logger.notempty partial
517:               end
518:             else
519:               logger.missing partial
520:             end
521:             parts.pop
522:           end
523:         end

Remove a file if it exists and is a file.

[Source]

     # File vendor/rails/railties/lib/rails_generator/commands.rb, line 444
444:         def file(relative_source, relative_destination, file_options = {})
445:           destination = destination_path(relative_destination)
446:           if File.exist?(destination)
447:             logger.rm relative_destination
448:             unless options[:pretend]
449:               if options[:svn]
450:                 # If the file has been marked to be added
451:                 # but has not yet been checked in, revert and delete
452:                 if options[:svn][relative_destination]
453:                   system("svn revert #{destination}")
454:                   FileUtils.rm(destination)
455:                 else
456:                 # If the directory is not in the status list, it
457:                 # has no modifications so we can simply remove it
458:                   system("svn rm #{destination}")
459:                 end
460:               elsif options[:git]
461:                 if options[:git][:new][relative_destination]
462:                   # file has been added, but not committed
463:                   system("git reset HEAD #{relative_destination}")
464:                   FileUtils.rm(destination)
465:                 elsif options[:git][:modified][relative_destination]
466:                   # file is committed and modified
467:                   system("git rm -f #{relative_destination}")
468:                 else
469:                   # If the directory is not in the status list, it
470:                   # has no modifications so we can simply remove it
471:                   system("git rm #{relative_destination}")
472:                 end
473:               else
474:                 FileUtils.rm(destination)
475:               end
476:             end
477:           else
478:             logger.missing relative_destination
479:             return
480:           end
481:         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 530
530:         def migration_template(relative_source, relative_destination, template_options = {})
531:           migration_directory relative_destination
532: 
533:           migration_file_name = template_options[:migration_file_name] || file_name
534:           unless migration_exists?(migration_file_name)
535:             puts "There is no migration named #{migration_file_name}"
536:             return
537:           end
538: 
539: 
540:           existing_migrations(migration_file_name).each do |file_path|
541:             file(relative_source, file_path, template_options)
542:           end
543:         end

[Source]

     # File vendor/rails/railties/lib/rails_generator/commands.rb, line 545
545:         def route_resources(*resources)
546:           resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
547:           look_for = "\n  map.resources #{resource_list}\n"
548:           logger.route "map.resources #{resource_list}"
549:           gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
550:         end
template(relative_source, relative_destination, file_options = {})

Alias for file

[Validate]