2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

Refactor temp directory methods into helper module

This commit is contained in:
Ryland Herrick and Vipul A M 2013-06-30 13:54:45 -05:00 committed by Ryland Herrick
parent 3c38062802
commit 591a5c0e13
5 changed files with 68 additions and 25 deletions

22
lib/directory_helper.rb Normal file
View file

@ -0,0 +1,22 @@
module DirectoryHelper
def tmp_directory(prefix)
directory_cache[prefix] ||= begin
f = File.join( Rails.root, 'tmp', Time.now.strftime("#{prefix}%Y%m%d%H%M%S") )
FileUtils.mkdir_p(f) unless Dir[f].present?
f
end
end
def remove_tmp_directory(prefix)
tmp_directory_name = directory_cache[prefix] || ''
directory_cache.delete(prefix)
FileUtils.rm_rf(tmp_directory_name) if Dir[tmp_directory_name].present?
end
private
def directory_cache
@directory_cache ||= {}
end
end