Class: RTeX::Tempdir

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

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_path, basename = 'rtex') ⇒ Tempdir

Returns a new instance of Tempdir.



19
20
21
22
23
# File 'lib/rtex/tempdir.rb', line 19

def initialize(parent_path, basename='rtex')
  @parent_path = parent_path
  @basename = basename
  @removed = false
end

Class Method Details

.open(parent_path = RTeX::Document.options[:tempdir]) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rtex/tempdir.rb', line 7

def self.open(parent_path=RTeX::Document.options[:tempdir])
  tempdir = new(parent_path)
  FileUtils.mkdir_p tempdir.path
  result = Dir.chdir(tempdir.path) do
    yield tempdir
  end
  # We don't remove the temporary directory when exceptions occur,
  # so that the source of the exception can be dubbed (logfile kept)
  tempdir.remove!
  result
end

Instance Method Details

#pathObject



25
26
27
# File 'lib/rtex/tempdir.rb', line 25

def path
  @path ||= File.expand_path(File.join(@parent_path, 'rtex', "#{@basename}-#{uuid}"))
end

#remove!Object



29
30
31
32
33
# File 'lib/rtex/tempdir.rb', line 29

def remove!
  return false if @removed
  FileUtils.rm_rf path
  @removed = true
end