Module: EacRubyUtils::Fs::Temp

Defined in:
lib/eac_ruby_utils/fs/temp.rb,
lib/eac_ruby_utils/fs/temp/file.rb,
lib/eac_ruby_utils/fs/temp/directory.rb

Overview

Utilities for temporary files.

Defined Under Namespace

Classes: Directory, File

Class Method Summary collapse

Class Method Details

.directory(*tempfile_args) ⇒ Pathname

Shortcut to EacRubyUtils::Fs::Temp::Directory.new(*tempfile_args).

Returns:


17
18
19
# File 'lib/eac_ruby_utils/fs/temp.rb', line 17

def directory(*tempfile_args)
  ::EacRubyUtils::Fs::Temp::Directory.new(*tempfile_args)
end

.file(*tempfile_args) ⇒ Pathname

Shortcut to EacRubyUtils::Fs::Temp::File.new(*tempfile_args).

Returns:


24
25
26
# File 'lib/eac_ruby_utils/fs/temp.rb', line 24

def file(*tempfile_args)
  ::EacRubyUtils::Fs::Temp::File.new(*tempfile_args)
end

.on_directory(*tempfile_args) ⇒ Object

Run a block while a temporary directory pathname is provided. The directory is deleted when the block is finished.


30
31
32
33
34
35
36
37
# File 'lib/eac_ruby_utils/fs/temp.rb', line 30

def on_directory(*tempfile_args)
  temp_dir = directory(*tempfile_args)
  begin
    yield(temp_dir)
  ensure
    temp_dir.remove
  end
end

.on_file(*tempfile_args) ⇒ Object

Run a block while a temporary file pathname is providade. The file is deleted when block is finished.


41
42
43
44
45
46
47
48
# File 'lib/eac_ruby_utils/fs/temp.rb', line 41

def on_file(*tempfile_args)
  temp_file = file(*tempfile_args)
  begin
    yield(temp_file)
  ensure
    temp_file.remove
  end
end