Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add Tempfile.delete_all method to delete all files generated by Tempf…

…ile class
  • Loading branch information...
commit ef45de4dbfb924a022f6df32b0b127924057fb30 1 parent c541ee1
@ak-mochi ak-mochi authored
Showing with 18 additions and 0 deletions.
  1. +18 −0 mrblib/tempfile.rb
View
18 mrblib/tempfile.rb
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
class Tempfile < File
+ @@tempfiles = []
+
def initialize(basename, tempdir = Dir::tmpdir)
self._bless
@deleted = false
@@ -10,6 +12,10 @@ def initialize(basename, tempdir = Dir::tmpdir)
@path = @path || make_tmpname(basename, tempdir)
super(@path, @mode, @perm)
+
+ @@tempfiles << self
+
+ self
end
def self.open(basename, tempdir = Dir::tmpdir, &block)
@@ -28,6 +34,17 @@ def self.open(basename, tempdir = Dir::tmpdir, &block)
end
+ def self.delete_all
+ while not @@tempfiles.empty?
+ @@tempfiles.shift.delete
+ end
+
+ end
+
+ def self.tempfiles
+ @@tempfiles
+ end
+
def make_tmpname(basename, tempdir, n=nil)
rand_max = 0x100000000
t = Time.now
@@ -87,6 +104,7 @@ def close!
def delete
File.delete(@path)
@deleted = true
+ @@tempfiles.delete(self)
self
end
Please sign in to comment.
Something went wrong with that request. Please try again.