Class: EacRubyUtils::Fs::Temp::File

Inherits:
Pathname show all
Defined in:
lib/eac_ruby_utils/fs/temp/file.rb

Direct Known Subclasses

Directory

Instance Method Summary collapse

Methods inherited from Pathname

#assert_parent, #basename_noext, #basename_sub, #child_of?, #if_exist, #mkpath_s, #parent_n, #readlink_r, #reqdir_glob

Constructor Details

#initialize(*tempfile_args) ⇒ File

Temporary file



11
12
13
14
15
16
17
# File 'lib/eac_ruby_utils/fs/temp/file.rb', line 11

def initialize(*tempfile_args)
  file = Tempfile.new(*tempfile_args)
  path = file.path
  file.close
  file.unlink
  super(path)
end

Instance Method Details

#removeObject



19
20
21
22
23
24
25
# File 'lib/eac_ruby_utils/fs/temp/file.rb', line 19

def remove
  if directory?
    rmtree
  elsif file?
    unlink
  end
end

#remove!Object



27
28
29
30
# File 'lib/eac_ruby_utils/fs/temp/file.rb', line 27

def remove!
  remove
  raise "Tried to remove \"#{self}\", but it yet exists" if exist?
end