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.
# File vendor/rails/railties/lib/rails_generator/commands.rb, line 509 509: def complex_template(*args) 510: # nothing should be done here 511: end
Remove each directory in the given path from right to left. Remove each subdirectory if it exists and is a directory.
# File vendor/rails/railties/lib/rails_generator/commands.rb, line 473 473: def directory(relative_path) 474: parts = relative_path.split('/') 475: until parts.empty? 476: partial = File.join(parts) 477: path = destination_path(partial) 478: if File.exist?(path) 479: if Dir[File.join(path, '*')].empty? 480: logger.rmdir partial 481: unless options[:pretend] 482: if options[:svn] 483: # If the directory has been marked to be added 484: # but has not yet been checked in, revert and delete 485: if options[:svn][relative_path] 486: system("svn revert #{path}") 487: FileUtils.rmdir(path) 488: else 489: # If the directory is not in the status list, it 490: # has no modifications so we can simply remove it 491: system("svn rm #{path}") 492: end 493: # I don't think git needs to remove directories?.. 494: # or maybe they have special consideration... 495: else 496: FileUtils.rmdir(path) 497: end 498: end 499: else 500: logger.notempty partial 501: end 502: else 503: logger.missing partial 504: end 505: parts.pop 506: end 507: end
Remove a file if it exists and is a file.
# File vendor/rails/railties/lib/rails_generator/commands.rb, line 428 428: def file(relative_source, relative_destination, file_options = {}) 429: destination = destination_path(relative_destination) 430: if File.exist?(destination) 431: logger.rm relative_destination 432: unless options[:pretend] 433: if options[:svn] 434: # If the file has been marked to be added 435: # but has not yet been checked in, revert and delete 436: if options[:svn][relative_destination] 437: system("svn revert #{destination}") 438: FileUtils.rm(destination) 439: else 440: # If the directory is not in the status list, it 441: # has no modifications so we can simply remove it 442: system("svn rm #{destination}") 443: end 444: elsif options[:git] 445: if options[:git][:new][relative_destination] 446: # file has been added, but not committed 447: system("git reset HEAD #{relative_destination}") 448: FileUtils.rm(destination) 449: elsif options[:git][:modified][relative_destination] 450: # file is committed and modified 451: system("git rm -f #{relative_destination}") 452: else 453: # If the directory is not in the status list, it 454: # has no modifications so we can simply remove it 455: system("git rm #{relative_destination}") 456: end 457: else 458: FileUtils.rm(destination) 459: end 460: end 461: else 462: logger.missing relative_destination 463: return 464: end 465: end
When deleting a migration, it knows to delete every file named "[0-9]*_#{file_name}".
# File vendor/rails/railties/lib/rails_generator/commands.rb, line 514 514: def migration_template(relative_source, relative_destination, template_options = {}) 515: migration_directory relative_destination 516: 517: migration_file_name = template_options[:migration_file_name] || file_name 518: unless migration_exists?(migration_file_name) 519: puts "There is no migration named #{migration_file_name}" 520: return 521: end 522: 523: 524: existing_migrations(migration_file_name).each do |file_path| 525: file(relative_source, file_path, template_options) 526: end 527: end
# File vendor/rails/railties/lib/rails_generator/commands.rb, line 529 529: def route_resources(*resources) 530: resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') 531: look_for = "\n map.resources #{resource_list}\n" 532: logger.route "map.resources #{resource_list}" 533: gsub_file 'config/routes.rb', /(#{look_for})/mi, '' 534: end