Class: Macinbox::Collector
- Inherits:
-
Object
- Object
- Macinbox::Collector
- Defined in:
- lib/macinbox/collector.rb
Instance Method Summary collapse
- #add_temp_dir(temp_dir) ⇒ Object
- #cleanup! ⇒ Object
-
#initialize(preserve_temp_dirs: false) ⇒ Collector
constructor
A new instance of Collector.
- #on_cleanup(&block) ⇒ Object
- #remove_temp_dirs ⇒ Object
Constructor Details
#initialize(preserve_temp_dirs: false) ⇒ Collector
Returns a new instance of Collector.
6 7 8 9 10 |
# File 'lib/macinbox/collector.rb', line 6 def initialize(preserve_temp_dirs: false) @temp_dirs = [] @blocks = [] @preserve_temp_dirs = preserve_temp_dirs end |
Instance Method Details
#add_temp_dir(temp_dir) ⇒ Object
11 12 13 |
# File 'lib/macinbox/collector.rb', line 11 def add_temp_dir(temp_dir) @temp_dirs << temp_dir end |
#cleanup! ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/macinbox/collector.rb', line 28 def cleanup! @blocks.reverse.each do |block| block.call end remove_temp_dirs @blocks = [] @temp_dirs = [] end |
#on_cleanup(&block) ⇒ Object
25 26 27 |
# File 'lib/macinbox/collector.rb', line 25 def on_cleanup(&block) @blocks << block end |
#remove_temp_dirs ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/macinbox/collector.rb', line 14 def remove_temp_dirs if @preserve_temp_dirs temp_dir_args = @temp_dirs.reverse.map { |o| o.shellescape }.join(" \\\n") Logger.error "WARNING: Temporary files were not removed. Run this command to remove them:" Logger.error "sudo rm -rf #{temp_dir_args}" else @temp_dirs.reverse.each do |temp_dir| FileUtils.remove_dir(temp_dir) end end end |