2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-30 13:54:45 -05:00
|
|
|
module DirectoryHelper
|
|
|
|
|
|
|
|
def tmp_directory(prefix)
|
|
|
|
directory_cache[prefix] ||= begin
|
2017-07-27 20:20:09 -05:00
|
|
|
f = File.join(Rails.root, 'tmp', Time.now.strftime("#{prefix}%Y%m%d%H%M%S"))
|
2013-06-30 13:54:45 -05:00
|
|
|
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
|