Project

tmptation

0.0
No commit activity in last 3 years
No release in over 3 years
Classes that help safely manipulate temporary files and directories.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

Summary

Tmptation provides classes that help safely manipulate temporary files and directories. Especially useful for use in tests.

Features

  • easy garbage collection of all created tmp files and dirs with .delete_all
  • safe deletion - will refuse to delete non-tmp paths (as determined by Dir.tmpdir)

Examples

# TmpFile is a subclass of Tempfile, with a few additions

file = Tmptation::TmpFile.new('name', 'contents')

file.path.exist?  #=> true
file.closed?      #=> false
file.read         #=> "contents"

Tmptation::TmpFile.delete_all

file.path.exist?  #=> false
file.closed?      #=> true


# TmpDir behaves like Pathname, with a few additions

path = Tmptation::TmpDir.new
path.exist?  #=> true

Tmptation::TmpDir.delete_all
path.exist?  #=> false

Mixins

Tmptation also contains two mixins, SafeDeletable and SubclassTracking. They might be useful on their own. See the inline docs for more details.

Protip

If you use Tmptation in tests, add TmpFile.delete_all and TmpDir.delete_all to your global teardown method:

class MiniTest::Unit::TestCase
  def teardown
    TmpFile.delete_all
    TmpDir.delete_all
  end
end