Class: Rails::Generator::Commands::Destroy
- Inherits:
-
RewindBase
- Object
- Base
- Base
- RewindBase
- Rails::Generator::Commands::Destroy
- Defined in:
- lib/rails_generator/commands.rb
Overview
Undo the actions performed by a generator. Rewind the action manifest and attempt to completely erase the results of each action.
Instance Attribute Summary
Attributes inherited from Base
#args, #destination_root, #source_root
Attributes included from Options
Instance Method Summary collapse
- #complex_template(*args) ⇒ Object
-
#directory(relative_path) ⇒ Object
Remove each directory in the given path from right to left.
-
#file(relative_source, relative_destination, file_options = {}) ⇒ Object
(also: #template)
Remove a file if it exists and is a file.
-
#migration_template(relative_source, relative_destination, template_options = {}) ⇒ Object
When deleting a migration, it knows to delete every file named “[0-9]*_#file_name”.
- #route_resources(*resources) ⇒ Object
Methods inherited from RewindBase
Methods inherited from Base
#class_collisions, #dependency, #invoke!, #readme
Methods inherited from Base
#destination_path, #initialize, #manifest, #source_path
Methods included from Options
Constructor Details
This class inherits a constructor from Rails::Generator::Base
Instance Method Details
#complex_template(*args) ⇒ Object
473 474 475 |
# File 'lib/rails_generator/commands.rb', line 473 def complex_template(*args) # nothing should be done here end |
#directory(relative_path) ⇒ Object
Remove each directory in the given path from right to left. Remove each subdirectory if it exists and is a directory.
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/rails_generator/commands.rb', line 439 def directory(relative_path) parts = relative_path.split('/') until parts.empty? partial = File.join(parts) path = destination_path(partial) if File.exists?(path) if Dir[File.join(path, '*')].empty? logger.rmdir partial unless [:pretend] if [:svn] # If the directory has been marked to be added # but has not yet been checked in, revert and delete if [:svn][relative_path] system("svn revert #{path}") FileUtils.rmdir(path) else # If the directory is not in the status list, it # has no modifications so we can simply remove it system("svn rm #{path}") end else FileUtils.rmdir(path) end end else logger.notempty partial end else logger.missing partial end parts.pop end end |
#file(relative_source, relative_destination, file_options = {}) ⇒ Object Also known as: template
Remove a file if it exists and is a file.
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/rails_generator/commands.rb', line 407 def file(relative_source, relative_destination, = {}) destination = destination_path(relative_destination) if File.exists?(destination) logger.rm relative_destination unless [:pretend] if [:svn] # If the file has been marked to be added # but has not yet been checked in, revert and delete if [:svn][relative_destination] system("svn revert #{destination}") FileUtils.rm(destination) else # If the directory is not in the status list, it # has no modifications so we can simply remove it system("svn rm #{destination}") end else FileUtils.rm(destination) end end else logger.missing relative_destination return end end |
#migration_template(relative_source, relative_destination, template_options = {}) ⇒ Object
When deleting a migration, it knows to delete every file named “[0-9]*_#file_name”.
478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/rails_generator/commands.rb', line 478 def migration_template(relative_source, relative_destination, = {}) migration_directory relative_destination migration_file_name = [:migration_file_name] || file_name unless migration_exists?(migration_file_name) puts "There is no migration named #{migration_file_name}" return end existing_migrations(migration_file_name).each do |file_path| file(relative_source, file_path, ) end end |
#route_resources(*resources) ⇒ Object
493 494 495 496 497 498 |
# File 'lib/rails_generator/commands.rb', line 493 def route_resources(*resources) resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') look_for = "\n map.resources #{resource_list}\n" logger.route "map.resources #{resource_list}" gsub_file 'config/routes.rb', /(#{look_for})/mi, '' end |