lib/carrierwave/uploader/cache.rb in carrierwave-0.3.5.2 vs lib/carrierwave/uploader/cache.rb in carrierwave-0.4.0

- old
+ new

@@ -1,13 +1,31 @@ # encoding: utf-8 module CarrierWave + + class FormNotMultipart < UploadError + def message + "You tried to assign a String or a Pathname to an uploader, for security reasons, this is not allowed.\n\n If this is a file upload, please check that your upload form is multipart encoded." + end + end + + ## + # Generates a unique cache id for use in the caching system + # + # === Returns + # + # [String] a cache id in the format YYYYMMDD-HHMM-PID-RND + # + def self.generate_cache_id + Time.now.strftime('%Y%m%d-%H%M') + '-' + Process.pid.to_s + '-' + ("%04d" % rand(9999)) + end + module Uploader module Cache - depends_on CarrierWave::Uploader::Paths depends_on CarrierWave::Uploader::Callbacks + depends_on CarrierWave::Uploader::Configuration ## # Returns true if the uploader has been cached # # === Returns @@ -17,21 +35,10 @@ def cached? @cache_id end ## - # Override this in your Uploader to change the directory where files are cached. - # - # === Returns - # - # [String] a directory - # - def cache_dir - CarrierWave.config[:cache_dir] - end - - ## # Returns a String which uniquely identifies the currently cached file for later retrieval # # === Returns # # [String] a cache name, in the format YYYYMMDD-HHMM-PID-RND/filename.txt @@ -60,15 +67,11 @@ self.cache_id = CarrierWave.generate_cache_id unless cache_id @filename = new_file.filename self.original_filename = new_file.filename - if CarrierWave.config[:cache_to_cache_dir] - @file = new_file.copy_to(cache_path, CarrierWave.config[:permissions]) - else - @file = new_file - end + @file = new_file.copy_to(cache_path, permissions) end end end ## @@ -91,10 +94,10 @@ end private def cache_path - File.expand_path(File.join(cache_dir, cache_name), public) + File.expand_path(File.join(cache_dir, cache_name), root) end attr_reader :cache_id, :original_filename # We can override the full_original_filename method in other modules \ No newline at end of file