Class: ArTeX::Tempdir
- Inherits:
-
Object
- Object
- ArTeX::Tempdir
- Defined in:
- lib/artex/tempdir.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(parent_path, basename = 'artex') ⇒ Tempdir
constructor
A new instance of Tempdir.
- #path ⇒ Object
- #remove! ⇒ Object
Constructor Details
#initialize(parent_path, basename = 'artex') ⇒ Tempdir
Returns a new instance of Tempdir.
19 20 21 22 23 |
# File 'lib/artex/tempdir.rb', line 19 def initialize(parent_path, basename='artex') @parent_path = parent_path @basename = basename @removed = false end |
Class Method Details
.open(parent_path = ArTeX::Document.options[:tempdir]) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/artex/tempdir.rb', line 7 def self.open(parent_path=ArTeX::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/artex/tempdir.rb', line 25 def path @path ||= File.(File.join(@parent_path, 'artex', "#{@basename}-#{uuid}")) end |
#remove! ⇒ Object
29 30 31 32 33 |
# File 'lib/artex/tempdir.rb', line 29 def remove! return false if @removed FileUtils.rm_rf path @removed = true end |