Sha256: 5730f5e9effa2e473329e81751e0585fb2b2b94ba80f5b37faf06efd74224022

Contents?: true

Size: 607 Bytes

Versions: 6

Compression:

Stored size: 607 Bytes

Contents

# coding: utf-8
require 'tmpdir'

class Siege
  class TempFile
    class << self
      def with_content(content)
        new content
      end
    end

    attr_reader :name

    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

    def read
      File.read(@name)
    end

    def delete
      File.delete(@name)
    end

    def write(contents)
      file = File.new(@name, 'w')
      file.puts(contents)
      file.close

      at_exit { File.delete(@name) }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bombard-0.1.0 lib/siege/temp_file.rb
bombard-0.0.6 lib/siege/temp_file.rb
bombard-0.0.5 lib/siege/temp_file.rb
bombard-0.0.4 lib/siege/temp_file.rb
bombard-0.0.3 lib/siege/temp_file.rb
bombard-0.0.2 lib/siege/temp_file.rb