Class: Kindeditor::AssetUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- Kindeditor::AssetUploader
show all
- Defined in:
- app/uploaders/kindeditor/asset_uploader.rb
Constant Summary
collapse
- EXT_NAMES =
{:image => RailsKindeditor.upload_image_ext,
:flash => RailsKindeditor.upload_flash_ext,
:media => RailsKindeditor.upload_media_ext,
:file => RailsKindeditor.upload_file_ext}
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.save_upload_info? ⇒ Boolean
77
78
79
80
81
82
83
84
85
86
|
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 77
def self.save_upload_info?
begin
%w(asset file flash image media).each do |s|
"Kindeditor::#{s.camelize}".constantize
end
return true
rescue
return false
end
end
|
Instance Method Details
#cache_dir ⇒ Object
29
30
31
|
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 29
def cache_dir
"#{Rails.root}/tmp/uploads"
end
|
#delete_tmp_dir(new_file) ⇒ Object
63
64
65
66
67
68
|
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 63
def delete_tmp_dir(new_file)
if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
FileUtils.rm_rf(File.join(cache_dir, @cache_id_was))
end
end
|
#filename ⇒ Object
70
71
72
73
74
75
|
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 70
def filename
if original_filename
@name ||= Digest::MD5.hexdigest(File.dirname(current_path)).slice(0, 12)
"#{@name}.#{file.extension}"
end
end
|
#remember_cache_id(new_file) ⇒ Object
store! nil’s the cache_id after it finishes so we need to remember it for deletition
59
60
61
|
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 59
def remember_cache_id(new_file)
@cache_id_was = cache_id
end
|
#store_dir ⇒ Object
Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:
21
22
23
24
25
26
27
|
# File 'app/uploaders/kindeditor/asset_uploader.rb', line 21
def store_dir
if Kindeditor::AssetUploader.save_upload_info?
"#{RailsKindeditor.upload_store_dir}/#{model.class.to_s.underscore.gsub(/(kindeditor\/)|(_uploader)/, '')}/#{model.created_at.strftime("%Y%m")}"
else
"#{RailsKindeditor.upload_store_dir}/#{self.class.to_s.underscore.gsub(/(kindeditor\/)|(_uploader)/, '')}/#{Time.now.strftime("%Y%m")}"
end
end
|