| 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 484
484: def complex_template(*args)
485: # nothing should be done here
486: 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 450
450: def directory(relative_path)
451: parts = relative_path.split('/')
452: until parts.empty?
453: partial = File.join(parts)
454: path = destination_path(partial)
455: if File.exist?(path)
456: if Dir[File.join(path, '*')].empty?
457: logger.rmdir partial
458: unless options[:pretend]
459: if options[:svn]
460: # If the directory has been marked to be added
461: # but has not yet been checked in, revert and delete
462: if options[:svn][relative_path]
463: system("svn revert #{path}")
464: FileUtils.rmdir(path)
465: else
466: # If the directory is not in the status list, it
467: # has no modifications so we can simply remove it
468: system("svn rm #{path}")
469: end
470: else
471: FileUtils.rmdir(path)
472: end
473: end
474: else
475: logger.notempty partial
476: end
477: else
478: logger.missing partial
479: end
480: parts.pop
481: end
482: end
Remove a file if it exists and is a file.
# File vendor/rails/railties/lib/rails_generator/commands.rb, line 418
418: def file(relative_source, relative_destination, file_options = {})
419: destination = destination_path(relative_destination)
420: if File.exist?(destination)
421: logger.rm relative_destination
422: unless options[:pretend]
423: if options[:svn]
424: # If the file has been marked to be added
425: # but has not yet been checked in, revert and delete
426: if options[:svn][relative_destination]
427: system("svn revert #{destination}")
428: FileUtils.rm(destination)
429: else
430: # If the directory is not in the status list, it
431: # has no modifications so we can simply remove it
432: system("svn rm #{destination}")
433: end
434: else
435: FileUtils.rm(destination)
436: end
437: end
438: else
439: logger.missing relative_destination
440: return
441: end
442: 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 489
489: def migration_template(relative_source, relative_destination, template_options = {})
490: migration_directory relative_destination
491:
492: migration_file_name = template_options[:migration_file_name] || file_name
493: unless migration_exists?(migration_file_name)
494: puts "There is no migration named #{migration_file_name}"
495: return
496: end
497:
498:
499: existing_migrations(migration_file_name).each do |file_path|
500: file(relative_source, file_path, template_options)
501: end
502: end
# File vendor/rails/railties/lib/rails_generator/commands.rb, line 504
504: def route_resources(*resources)
505: resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
506: look_for = "\n map.resources #{resource_list}\n"
507: logger.route "map.resources #{resource_list}"
508: gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
509: end