Class: Upload
Constant Summary
AnotherUploader::MimeTypeGetters::MTG
UploadBehavior::MTG
Instance Method Summary
collapse
#transliterate, #transliterate_file_name
#is_excel?, #is_image?, #is_mp3?, #is_of_type?, #is_pdf?, #is_text?, #is_word?
#calculate_sizes, #dimension, #image_ratio, #max_dimension
#icon_name, #icon_path
Instance Method Details
#can_edit?(user) ⇒ Boolean
85
86
87
|
# File 'app/models/upload.rb', line 85
def can_edit?(user)
!user.blank? && user == self.creator
end
|
#content_type ⇒ Object
53
|
# File 'app/models/upload.rb', line 53
def content_type; file_attribute(:content_type); end
|
#display_name ⇒ Object
81
82
83
|
# File 'app/models/upload.rb', line 81
def display_name
CGI::escapeHTML(self.file_name)
end
|
#exists_locally? ⇒ Boolean
48
|
# File 'app/models/upload.rb', line 48
def exists_locally?; local.exists?; end
|
#exists_remotely? ⇒ Boolean
49
|
# File 'app/models/upload.rb', line 49
def exists_remotely?; remote.exists?; end
|
#file ⇒ Object
51
|
# File 'app/models/upload.rb', line 51
def file; file_attribute(""); end
|
#file=(f) ⇒ Object
57
58
59
60
61
62
|
# File 'app/models/upload.rb', line 57
def file=(f)
self.name = f.original_filename
f.content_type = MIME::Types.type_for(name)[0].to_s
self.remote = nil
self.local = f
end
|
#file_name ⇒ Object
52
|
# File 'app/models/upload.rb', line 52
def file_name; file_attribute(:file_name); end
|
#file_size ⇒ Object
54
|
# File 'app/models/upload.rb', line 54
def file_size; file_attribute(:file_size); end
|
#fingerprint ⇒ Object
55
|
# File 'app/models/upload.rb', line 55
def fingerprint; file_attribute(:fingerprint); end
|
#height(style = :default) ⇒ Object
91
|
# File 'app/models/upload.rb', line 91
def height(style = :default); dimension :height, style; end
|
#icon ⇒ Object
72
73
74
|
# File 'app/models/upload.rb', line 72
def icon
self.is_image? ? self.file.url(:icon) : icon_path
end
|
#send_to_remote ⇒ Object
64
65
66
67
68
69
70
|
# File 'app/models/upload.rb', line 64
def send_to_remote
raise Paperclip::Error, "The local file is dirty. Please save the upload before calling send_to_remote" if local.dirty?
if local_file_name
self.remote = Paperclip.io_adapters.for(local)
local.destroy if self.save && !AnotherUploader.configuration.keep_local_file && remote.exists?
end
end
|
#size(style = :default) ⇒ Object
93
94
95
96
97
98
|
# File 'app/models/upload.rb', line 93
def size(style = :default)
return nil unless width || height
return "#{width}x#{height}" if style == :default
calculate_sizes(style.to_sym)
return @image_size
end
|
#thumb ⇒ Object
76
77
78
|
# File 'app/models/upload.rb', line 76
def thumb
self.file.url(:thumb) if self.is_image?
end
|
#width(style = :default) ⇒ Object
89
|
# File 'app/models/upload.rb', line 89
def width(style = :default); dimension :width, style; end
|