summaryrefslogtreecommitdiff
path: root/lib/temporary_storage.rb
blob: 2eb5f0607d5a8ef369aa63b1511b83f055c3338e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class TemporaryStorage
  def store(file)
    "#{tmp_dir}/#{File.basename(file.path).parameterize}".tap do |new_path|
      Rails.logger.debug("Copying... #{file.path} to #{new_path}")
      FileUtils.cp(file.path, new_path)
    end
  end

  private

  def tmp_dir
    Rails.root.join("tmp/uploads/#{SecureRandom.uuid}").tap do |directory|
      system "mkdir -p #{directory}"
    end
  end
end