Sha256: 6f80c93a71a0de2c332b5d8591983440839db7b4ab25162f2b485c5621b688f7

Contents?: true

Size: 494 Bytes

Versions: 2

Compression:

Stored size: 494 Bytes

Contents

#--
# Copyright protects this work.
# See LICENSE file for details.
#++

require 'tempfile'
require 'fileutils'

class TempDir
  attr_reader :path

  def initialize basename = nil, dirname = nil
    args = [basename || File.basename($0), dirname].compact
    file = Tempfile.new(*args)

    @path = file.path

    # replace the file with a directory
    file.close!
    FileUtils.mkdir_p @path

    # clean up on exit
    at_exit { close }
  end

  def close
    FileUtils.rm_rf @path
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
inochi-1.1.1 lib/inochi/util/tempdir.rb
inochi-1.1.0 lib/inochi/util/tempdir.rb