Module: Tap::Generator::Destroy

Extended by:
Lazydoc::Attributes
Defined in:
lib/tap/generator/destroy.rb

Overview

::mixin run generators in reverse

A mixin defining how to run manifest actions in reverse.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(argv = ARGV, app = Tap::App.current, &block) ⇒ Object



13
14
15
# File 'lib/tap/generator/destroy.rb', line 13

def self.parse(argv=ARGV, app=Tap::App.current, &block)
  Base.parse_as(self, argv, app, &block)
end

Instance Method Details

#actionObject

Returns :destroy



70
71
72
# File 'lib/tap/generator/destroy.rb', line 70

def action
  :destroy
end

#directory(target, options = {}) ⇒ Object

Removes the target directory if it exists. Missing, non-directory and non-empty targets are simply logged and not removed. When pretend is true, removal is logged but does not actually happen.

No options currently affect the behavior of this method.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tap/generator/destroy.rb', line 29

def directory(target, options={})
  target = path(target)
  
  case
  when !File.exists?(target)
    log_relative :missing, target
  when !File.directory?(target)
    log_relative 'not a directory', target
  when target == Dir.pwd
  when !Root.empty?(target)
    log_relative 'not empty', target
  else
    log_relative :rm, target
    FileUtils.rmdir(target) unless pretend
  end
  
  target
end

#file(target, options = {}) ⇒ Object

Removes the target file if it exists. Missing and non-file and targets are simply logged and not removed. When pretend is true, removal is logged but does not actually happen.

No options currently affect the behavior of this method.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tap/generator/destroy.rb', line 53

def file(target, options={})
  target = path(target)
  
  case
  when File.file?(target)
    log_relative :rm, target
    FileUtils.rm(target) unless pretend
  when File.directory?(target)
    log_relative 'not a file', target
  else
    log_relative :missing, target
  end
  
  target
end

#iterate(actions) ⇒ Object

Iterates over the actions in reverse, and collects the results.



18
19
20
21
22
# File 'lib/tap/generator/destroy.rb', line 18

def iterate(actions)
  results = []
  actions.reverse_each {|action| results << yield(action) }
  results
end

#to_specObject



74
75
76
77
78
# File 'lib/tap/generator/destroy.rb', line 74

def to_spec
  spec = super
  spec['mixin'] = 'Tap::Generator::Destroy'
  spec
end