9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/yogo/collection/asset/model_properties.rb', line 9
def self.extended(model)
uploader = Class.new(CarrierWave::Uploader::Base)
uploader.storage(:file)
uploader.class_eval %{
def store_dir
File.join('#{Configuration.collection.asset.storage_dir}', '#{model.collection.collection_storage_name}')
end
def filename
# Digest::MD5.hexdigest(self.read)
UUIDTools::UUID.timestamp_create
end
}, __FILE__, __LINE__+1
model.class_eval do
without_auto_validations do
property :content_type, String
property :description, String
property :asset_file, String
property :original_filename, String
end
mount_uploader :file, uploader, :mount_on => :asset_file
after :file=, :write_file_identifier
after :file=, :set_original_filename
private
def set_original_filename
attribute_set(:original_filename, file.send(:original_filename))
end
end
end
|