class TmpDirectory

Attributes

path[R]

Public Class Methods

new(name="tmp") click to toggle source
# File lib/tmp_directory.rb, line 7
def initialize name="tmp"
  @path = ::File.join(Dir.tmpdir, "#{name}-#{Time.now.strftime("%Y%m%d%H%M%S")}-#{Random.rand}")
  
  FileUtils.mkdir_p @path
  
  #Add shutdown hook to remove tar tmp directory
  Kernel.at_exit do 
    cleanup
  end
end

Private Instance Methods

cleanup() click to toggle source

Remove the created temp directory

# File lib/tmp_directory.rb, line 21
def cleanup
  FileUtils.rm_rf @path
end