Class: TempDir

Inherits:
Object
  • Object
show all
Defined in:
lib/inochi/util/tempdir.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(basename = nil, dirname = nil) ⇒ TempDir



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/inochi/util/tempdir.rb', line 12

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/inochi/util/tempdir.rb', line 10

def path
  @path
end

Instance Method Details

#closeObject



26
27
28
# File 'lib/inochi/util/tempdir.rb', line 26

def close
  FileUtils.rm_rf @path
end