Class: Apimaster::Generators::Destroy
- Inherits:
-
RewindBase
- Object
- Base
- Command
- RewindBase
- Apimaster::Generators::Destroy
- Defined in:
- lib/apimaster/generators/command.rb
Overview
Undo the actions performed by a generator. Rewind the action manifest and attempt to completely erase the results of each action.
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#active, #args, #destination_root, #logger, #source_root, #spec, #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 Command
#class_collisions, #dependency, #destination_path, #invoke!, #readme, #source_path, #write_manifest
Methods inherited from Base
#after_generate, #base_name, #camelize, #destination_path, #initialize, #manifest, #pluralize, #run, #source_path
Methods included from Options
Constructor Details
This class inherits a constructor from Apimaster::Generators::Base
Instance Method Details
#complex_template(*args) ⇒ Object
589 590 591 |
# File 'lib/apimaster/generators/command.rb', line 589 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.
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'lib/apimaster/generators/command.rb', line 553 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.
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/apimaster/generators/command.rb', line 508 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”.
594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/apimaster/generators/command.rb', line 594 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
609 610 611 612 613 614 |
# File 'lib/apimaster/generators/command.rb', line 609 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 |