Created
May 22, 2009 16:11
-
-
Save stefanpenner/116221 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# helpfull for performing actions that require temp directories | |
# 1. handles temp file creation | |
# 2. lets you do your business in da 'block' | |
# 3. cleans up after itself | |
# usage | |
require 'fileutils' | |
include FileUtils | |
temp do | |
mkdir_p 'some/long/path' | |
touch 'some compile stuff etc.etc.' | |
end | |
# now its all cleaned up | |
# implementation | |
def temp | |
@timestamp ||= Time.now.to_i | |
dir = "/tmp/backup+#{@timestamp}" | |
mkdir_p dir | |
begin | |
cd dir do | |
yield | |
end | |
ensure | |
rm_rf dir | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment