Module: Tap::Generator::Destroy
- Defined in:
- lib/tap/generator/destroy.rb
Overview
A mixin defining how to run manifest actions in reverse.
Instance Method Summary collapse
-
#directory(target, options = {}) ⇒ Object
Removes the target directory if it exists.
-
#file(target, options = {}) ⇒ Object
Removes the target file if it exists.
-
#iterate(actions) ⇒ Object
Iterates over the actions in reverse.
Instance Method Details
#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.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tap/generator/destroy.rb', line 17 def directory(target, ={}) target = File.(target) case when !File.exists?(target) log_relative :missing, target when !File.directory?(target) log_relative 'not a directory', target when !Root.empty?(target) log_relative 'not empty', target else log_relative :rm, target FileUtils.rmdir(target) unless pretend end 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.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tap/generator/destroy.rb', line 38 def file(target, ={}) target = File.(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 end |
#iterate(actions) ⇒ Object
Iterates over the actions in reverse.
8 9 10 |
# File 'lib/tap/generator/destroy.rb', line 8 def iterate(actions) actions.reverse_each {|action| yield(action) } end |