Class: PolymorphicUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- PolymorphicUploader
- Defined in:
- app/uploaders/polymorphic_uploader.rb
Class Method Summary collapse
-
.cache_dir ⇒ Object
This is where files are stored on upload.
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #delete_tmp_dir(_new_file) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(*args) ⇒ PolymorphicUploader
constructor
A new instance of PolymorphicUploader.
-
#remember_cache_id(_new_file) ⇒ Object
store! nils the cache_id after it finishes so we need to remember it for deletion.
Constructor Details
#initialize(*args) ⇒ PolymorphicUploader
Returns a new instance of PolymorphicUploader.
80 81 82 |
# File 'app/uploaders/polymorphic_uploader.rb', line 80 def initialize(*args, &) super end |
Class Method Details
.cache_dir ⇒ Object
This is where files are stored on upload. We are using callbacks to empty it after upload
92 93 94 |
# File 'app/uploaders/polymorphic_uploader.rb', line 92 def self.cache_dir "#{Rails.root}/tmp/uploads" end |
Instance Method Details
#cache_dir ⇒ Object
96 97 98 |
# File 'app/uploaders/polymorphic_uploader.rb', line 96 def cache_dir self.class.cache_dir end |
#delete_tmp_dir(_new_file) ⇒ Object
108 109 110 111 |
# File 'app/uploaders/polymorphic_uploader.rb', line 108 def delete_tmp_dir(_new_file) # make sure we don't delete other things accidentally by checking the name pattern FileUtils.rm_rf(File.join(cache_dir, @cache_id_was)) if @cache_id_was.present? && @cache_id_was =~ /\A[\d-]*\z/ end |
#exists? ⇒ Boolean
84 85 86 |
# File 'app/uploaders/polymorphic_uploader.rb', line 84 def exists? @column.blank? end |
#remember_cache_id(_new_file) ⇒ Object
store! nils the cache_id after it finishes so we need to remember it for deletion
104 105 106 |
# File 'app/uploaders/polymorphic_uploader.rb', line 104 def remember_cache_id(_new_file) @cache_id_was = cache_id end |