Sha256: d0e259dbb83da32d20ca94eb102c8f9f6f93deb5221d578a28c08580dee377a7

Contents?: true

Size: 558 Bytes

Versions: 4

Compression:

Stored size: 558 Bytes

Contents

require 'tmpdir'
module Astrails
  module Safe
    module TmpFile
      @keep_files = []

      def self.tmproot
        @tmproot ||= Dir.mktmpdir
      end

      def self.cleanup
        FileUtils.remove_entry_secure tmproot
        @tmproot = nil
      end

      def self.create(name)
        # create temp directory

        file = Tempfile.new(name, tmproot)

        yield file

        file.close
        @keep_files << file # so that it will not get gcollected and removed from filesystem until the end
        file.path
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
astrails-safe-0.1.10 lib/astrails/safe/tmp_file.rb
astrails-safe-0.1.7 lib/astrails/safe/tmp_file.rb
astrails-safe-0.1.8 lib/astrails/safe/tmp_file.rb
astrails-safe-0.1.9 lib/astrails/safe/tmp_file.rb