Class: Rails::Generator::Commands::Destroy

Inherits:
RewindBase show all
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

Instance Method Summary collapse

Methods inherited from RewindBase

#invoke!

Methods inherited from Base

#class_collisions, #dependency, #invoke!, #readme

Methods inherited from Base

#destination_path, #initialize, #manifest, #source_path

Constructor Details

This class inherits a constructor from Rails::Generator::Base

Instance Method Details

#complex_template(*args) ⇒ Object



333
334
335
# File 'lib/rails_generator/commands.rb', line 333

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.



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/rails_generator/commands.rb', line 314

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
        FileUtils.rmdir(path) unless options[:pretend]
      else
        logger.notempty partial
      end
    else
      logger.missing partial
    end
    parts.pop
  end
end

#file(relative_source, relative_destination, options = {}) ⇒ Object Also known as: template

Remove a file if it exists and is a file.



297
298
299
300
301
302
303
304
305
306
# File 'lib/rails_generator/commands.rb', line 297

def file(relative_source, relative_destination, options = {})
  destination = destination_path(relative_destination)
  if File.exists?(destination)
    logger.rm relative_destination
    FileUtils.rm(destination) unless options[:pretend]
  else
    logger.missing relative_destination
    return
  end
end