Class: RubiGen::Commands::Destroy
- Inherits:
-
RewindBase
- Object
- Base
- Base
- RewindBase
- RubiGen::Commands::Destroy
- Defined in:
- lib/rubigen/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, #stdout
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, #write_manifest
Methods inherited from Base
#after_generate, #base_name, #destination_path, #initialize, #manifest, #source_path
Methods included from Options
Constructor Details
This class inherits a constructor from RubiGen::Base
Instance Method Details
#complex_template(*args) ⇒ Object
575 576 577 |
# File 'lib/rubigen/commands.rb', line 575 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.
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
# File 'lib/rubigen/commands.rb', line 539 def directory(relative_path) parts = relative_path.split('/') until parts.empty? partial = File.join(parts) path = destination_path(partial) if File.exist?(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 # I don't think git needs to remove directories?.. # or maybe they have special consideration... 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.
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/rubigen/commands.rb', line 494 def file(relative_source, relative_destination, = {}) destination = destination_path(relative_destination) if File.exist?(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 elsif [:git] if [:git][:new][relative_destination] # file has been added, but not committed system("git reset HEAD #{relative_destination}") FileUtils.rm(destination) elsif [:git][:modified][relative_destination] # file is committed and modified system("git rm -f #{relative_destination}") else # If the directory is not in the status list, it # has no modifications so we can simply remove it system("git rm #{relative_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”.
580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'lib/rubigen/commands.rb', line 580 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) stdout.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
595 596 597 598 599 600 |
# File 'lib/rubigen/commands.rb', line 595 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 |