class Siege::TempFile

Attributes

name[R]

Public Class Methods

new(content = nil) click to toggle source
# File lib/siege/temp_file.rb, line 14
def initialize(content = nil)
  file  = [rand(6_251_983), '_', Time.now.to_i].join
  @name = File.expand_path(file, Dir.tmpdir)
  write(content) if content
end
with_content(content) click to toggle source
# File lib/siege/temp_file.rb, line 7
def with_content(content)
  new content
end

Public Instance Methods

delete() click to toggle source
# File lib/siege/temp_file.rb, line 24
def delete
  File.delete(@name)
end
read() click to toggle source
# File lib/siege/temp_file.rb, line 20
def read
  File.read(@name)
end
write(contents) click to toggle source
# File lib/siege/temp_file.rb, line 28
def write(contents)
  file = File.new(@name, 'w')
  file.puts(contents)
  file.close

  at_exit { File.delete(@name) }
end