Class: RTeX::Tempdir
- Inherits:
-
Object
- Object
- RTeX::Tempdir
- Defined in:
- lib/rtex/tempdir.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(parent_path, basename = 'rtex') ⇒ Tempdir
constructor
A new instance of Tempdir.
- #path ⇒ Object
- #remove! ⇒ Object
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.[: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
#path ⇒ Object
25 26 27 |
# File 'lib/rtex/tempdir.rb', line 25 def path @path ||= File.(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 |