Module: EacRubyUtils::Fs::Temp
- Defined in:
- lib/eac_ruby_utils/fs/temp.rb
Overview
Utilities for temporary files.
Class Method Summary collapse
- .file(*tempfile_args) ⇒ Pathname
-
.on_file(*tempfile_args) ⇒ Object
Run a block while a temporary file pathname is providade.
Class Method Details
.file(*tempfile_args) ⇒ Pathname
12 13 14 15 16 17 18 |
# File 'lib/eac_ruby_utils/fs/temp.rb', line 12 def file(*tempfile_args) file = Tempfile.new(*tempfile_args) r = ::Pathname.new(file.path) file.close file.unlink r end |
.on_file(*tempfile_args) ⇒ Object
Run a block while a temporary file pathname is providade. The file is deleted when block is finished.
22 23 24 25 26 27 28 29 |
# File 'lib/eac_ruby_utils/fs/temp.rb', line 22 def on_file(*tempfile_args) pathname = file(*tempfile_args) begin yield(pathname) ensure pathname.unlink if pathname.exist? end end |