Class: ViewServer::TmpFile

Inherits:
Object
  • Object
show all
Defined in:
lib/view_server/tmp_file.rb

Class Method Summary collapse

Class Method Details

.open(prefix = "", suffix = "") ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/view_server/tmp_file.rb', line 7

def self.open(prefix = "", suffix= "")
  begin
    digest = Digest::MD5.hexdigest((Time.now.to_f + rand(10000)).to_s)
    file_name = File.join(Dir.tmpdir, prefix + digest + suffix )
    File.open(file_name, 'w+' ) do |f|
      yield f 
    end
  ensure
    FileUtils::rm(file_name) if File.exist?(file_name)
  end
end