Class: RubiGen::Commands::Destroy

### Home Classes Methods

### In Files

- lib/rubigen/commands.rb

### Parent

RubiGen::Commands::RewindBase

### Methods

- #complex_template
- #directory
- #file
- #migration_template
- #route_resources
- #template

### Files

- History.txt
- License.txt
- Manifest.txt
- Todo.txt
- README.txt
- index.txt
- version-raw.txt
- version.txt

### Class/Module Index

Quicksearch

- RubiGen
- RubiGen::AbstractGemSource
- RubiGen::Base
- RubiGen::Commands
- RubiGen::Commands::Base
- RubiGen::Commands::Create
- RubiGen::Commands::Destroy
- RubiGen::Commands::List
- RubiGen::Commands::RewindBase
- RubiGen::Commands::Update
- RubiGen::GemPathSource
- RubiGen::GeneratedAttribute
- RubiGen::GeneratorError
- RubiGen::GeneratorTestHelper
- RubiGen::Lookup
- RubiGen::Lookup::ClassMethods
- RubiGen::Manifest
- RubiGen::Options
- RubiGen::Options::ClassMethods
- RubiGen::PathFilteredSource
- RubiGen::PathSource
- RubiGen::Scripts
- RubiGen::Scripts::Base
- RubiGen::Scripts::Destroy
- RubiGen::Scripts::Generate
- RubiGen::Scripts::Update
- RubiGen::Source
- RubiGen::Spec
- RubiGen::UsageError
- Rubigen
- Rubigen::CLI
- Dir
- Object

No matching classes.

# RubiGen::Commands::Destroy

Undo the actions performed by a generator. Rewind the action manifest and attempt to completely erase the results of each action.

### Public Instance Methods

complex_template(*args) click to toggle source

    # File lib/rubigen/commands.rb, line 575
    def complex_template(*args)
      # nothing should be done here
    end

directory(relative_path) click to toggle source

Remove each directory in the given path from right to left. Remove each subdirectory if it exists and is a directory.

    # 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 options[:pretend]
              if options[:svn]
                # If the directory has been marked to be added
                # but has not yet been checked in, revert and delete
                if options[: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 = {}) click to toggle source

Remove a file if it exists and is a file.

    # File lib/rubigen/commands.rb, line 494
    def file(relative_source, relative_destination, file_options = {})
      destination = destination_path(relative_destination)
      if File.exist?(destination)
        logger.rm relative_destination
        unless options[:pretend]
          if options[:svn]
            # If the file has been marked to be added
            # but has not yet been checked in, revert and delete
            if options[: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 options[:git]
            if options[:git][:new][relative_destination]
              # file has been added, but not committed
              system("git reset HEAD #{relative_destination}")
              FileUtils.rm(destination)
            elsif options[: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

Also aliased as: template
migration_template(relative_source, relative_destination, template_options = {}) click to toggle source

When deleting a migration, it knows to delete every file named "[0-9]*_#{file_name}".

    # File lib/rubigen/commands.rb, line 580
    def migration_template(relative_source, relative_destination, template_options = {})
      migration_directory relative_destination

      migration_file_name = template_options[: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, template_options)
      end
    end

route_resources(*resources) click to toggle source

    # 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})/i, ''
    end

template(relative_source, relative_destination, file_options = {}) click to toggle source

Templates are deleted just like files and the actions take the same parameters, so simply alias the file method.

Alias for: file

[Validate]

Generated with the Darkfish Rdoc Generator 2.