Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Creates a temporary directory upon the first call but always returns its path
- # Stolen from Alex Chaffee's files-gem and
- # http://stackoverflow.com/questions/1139265/what-is-the-best-way-to-get-a-temporary-directory-in-ruby-on-rails
- def temp_dir options = {:remove => true}
- @temp_dir ||= begin
- @log.debug('creating temp_dir')
- require 'tmpdir'
- require 'fileutils'
- #
- # called_from = File.basename caller.first.split(':').first, ".rb"
- called_from = CremeFraiche::prog_info[:app_name].gsub(' ', '_')
- @log.debug('called_from is ' << called_from)
- path = File.join(Dir::tmpdir, "#{called_from}_#{Time.now.to_i}_#{rand(1000)}")
- @log.debug('temp-dir path is ' << path)
- Dir.mkdir(path)
- at_exit {FileUtils.rm_rf(path) if File.exists?(path)} if options[:remove]
- File.new path
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment