Module: Roo::Tempdir
- Included in:
- Excelx, OpenOffice
- Defined in:
- lib/roo/tempdir.rb
Instance Method Summary collapse
Instance Method Details
#finalize_tempdirs(object_id) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/roo/tempdir.rb', line 3 def finalize_tempdirs(object_id) if @tempdirs && (dirs_to_remove = @tempdirs[object_id]) @tempdirs[object_id] = nil dirs_to_remove.each do |dir| ::FileUtils.remove_entry(dir) end end end |
#make_tempdir(object, prefix, root) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/roo/tempdir.rb', line 12 def make_tempdir(object, prefix, root) root ||= ENV['ROO_TMP'] # folder is cleaned up in .finalize_tempdirs ::Dir.mktmpdir("#{Roo::TEMP_PREFIX}#{prefix}", root).tap do |tmpdir| @tempdirs ||= {} if @tempdirs[object.object_id] @tempdirs[object.object_id] << tmpdir else @tempdirs[object.object_id] = [tmpdir] ObjectSpace.define_finalizer(object, method(:finalize_tempdirs)) end end end |