Module: ActiveRecord::Acts::UploaderUpload::InstanceMethods
- Defined in:
- lib/active_record/acts/uploader_upload.rb
Overview
All the methods available to a record that has had acts_as_uploader specified.
Instance Method Summary collapse
- #calculate_sizes(style) ⇒ Object
- #can_edit?(check_user) ⇒ Boolean
- #determine_immediate_send_to_remote ⇒ Object
- #display_name ⇒ Object
- #file ⇒ Object
- #file_name ⇒ Object
- #height(style = :default) ⇒ Object
- #icon ⇒ Object
- #image_ratio ⇒ Object
- #is_excel? ⇒ Boolean
- #is_image? ⇒ Boolean
- #is_mp3? ⇒ Boolean
- #is_pdf? ⇒ Boolean
- #is_text? ⇒ Boolean
- #is_word? ⇒ Boolean
- #max_dimension(style) ⇒ Object
- #multiupload_local=(filedata) ⇒ Object
- #send_to_remote ⇒ Object
- #size(style = :default) ⇒ Object
-
#thumb ⇒ Object
Only works for images.
- #upload_type ⇒ Object
-
#width(style = :default) ⇒ Object
Image dimension calculations.
Instance Method Details
#calculate_sizes(style) ⇒ Object
230 231 232 233 234 235 236 237 238 239 |
# File 'lib/active_record/acts/uploader_upload.rb', line 230 def calculate_sizes(style) if image_ratio > 1 @image_width ||= width > max_dimension(style) ? max_dimension(style) : width @image_height ||= (@image_width / image_ratio).round else @image_height ||= height > max_dimension(style) ? max_dimension(style) : height @image_width ||= (@image_height * image_ratio).round end @image_size ||= "#{@image_width.to_i}x#{@image_height.to_i}" end |
#can_edit?(check_user) ⇒ Boolean
194 195 196 197 |
# File 'lib/active_record/acts/uploader_upload.rb', line 194 def can_edit?(check_user) return false if check_user.blank? check_user == self.creator end |
#determine_immediate_send_to_remote ⇒ Object
100 101 102 103 104 |
# File 'lib/active_record/acts/uploader_upload.rb', line 100 def determine_immediate_send_to_remote if self.class.s3_no_wait? self.remote = local.to_file # This will result in the file being sent to S3 end end |
#display_name ⇒ Object
190 191 192 |
# File 'lib/active_record/acts/uploader_upload.rb', line 190 def display_name CGI::escapeHTML(self.local_file_name) end |
#file ⇒ Object
92 93 94 |
# File 'lib/active_record/acts/uploader_upload.rb', line 92 def file local_file_name ? local : remote end |
#file_name ⇒ Object
96 97 98 |
# File 'lib/active_record/acts/uploader_upload.rb', line 96 def file_name remote_file_name || local_file_name end |
#height(style = :default) ⇒ Object
208 209 210 211 212 213 |
# File 'lib/active_record/acts/uploader_upload.rb', line 208 def height(style = :default) return nil unless self[:height] return self[:height] if style == :default calculate_sizes(style.to_sym) return @image_height.to_i end |
#icon ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/active_record/acts/uploader_upload.rb', line 165 def icon if self.is_pdf? '/images/file_icons/file_pdf.gif' elsif self.is_word? '/images/file_icons/file_doc.gif' elsif self.is_image? self.file.url(:icon) elsif self.is_mp3? '/images/file_icons/file_mp3.gif' elsif self.is_excel? '/images/file_icons/file_xls.gif' elsif self.is_text? '/images/file_icons/file_txt.gif' else '/images/file_icons/file_raw.gif' end end |
#image_ratio ⇒ Object
226 227 228 |
# File 'lib/active_record/acts/uploader_upload.rb', line 226 def image_ratio @image_ratio ||= width.to_f / height.to_f end |
#is_excel? ⇒ Boolean
131 132 133 |
# File 'lib/active_record/acts/uploader_upload.rb', line 131 def is_excel? Uploader::MimeTypeGroups::EXCEL_TYPES.include?(self.local_content_type) end |
#is_image? ⇒ Boolean
123 124 125 |
# File 'lib/active_record/acts/uploader_upload.rb', line 123 def is_image? Uploader::MimeTypeGroups::IMAGE_TYPES.include?(self.local_content_type) end |
#is_mp3? ⇒ Boolean
127 128 129 |
# File 'lib/active_record/acts/uploader_upload.rb', line 127 def is_mp3? Uploader::MimeTypeGroups::MP3_TYPES.include?(self.local_content_type) end |
#is_pdf? ⇒ Boolean
135 136 137 |
# File 'lib/active_record/acts/uploader_upload.rb', line 135 def is_pdf? Uploader::MimeTypeGroups::PDF_TYPES.include?(self.local_content_type) end |
#is_text? ⇒ Boolean
143 144 145 |
# File 'lib/active_record/acts/uploader_upload.rb', line 143 def is_text? Uploader::MimeTypeGroups::TEXT_TYPES.include?(self.local_content_type) end |
#is_word? ⇒ Boolean
139 140 141 |
# File 'lib/active_record/acts/uploader_upload.rb', line 139 def is_word? Uploader::MimeTypeGroups::WORD_TYPES.include?(self.local_content_type) end |
#max_dimension(style) ⇒ Object
222 223 224 |
# File 'lib/active_record/acts/uploader_upload.rb', line 222 def max_dimension(style) @max_dimension ||= Paperclip::Geometry.parse(self.local.styles[style][:geometry]).width.to_f end |
#multiupload_local=(filedata) ⇒ Object
118 119 120 121 |
# File 'lib/active_record/acts/uploader_upload.rb', line 118 def multiupload_local=(filedata) filedata.content_type = MIME::Types.type_for(filedata.original_filename)[0].to_s self.local = filedata end |
#send_to_remote ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/active_record/acts/uploader_upload.rb', line 106 def send_to_remote if local_file_name self.remote = local.to_file if self.save and remote.original_filename and remote.exists? self.local = nil unless keep_local_file? self.save else false end end end |
#size(style = :default) ⇒ Object
215 216 217 218 219 220 |
# File 'lib/active_record/acts/uploader_upload.rb', line 215 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
Only works for images
184 185 186 187 188 |
# File 'lib/active_record/acts/uploader_upload.rb', line 184 def thumb if self.is_image? self.file.url(:thumb) end end |
#upload_type ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/active_record/acts/uploader_upload.rb', line 147 def upload_type if self.is_pdf? 'Adobe pdf file' elsif self.is_word? 'Word document' elsif self.is_image? 'photo' elsif self.is_mp3? 'mp3' elsif self.is_excel? 'Excel document' elsif self.is_text? 'text file' else 'file' end end |
#width(style = :default) ⇒ Object
Image dimension calculations
201 202 203 204 205 206 |
# File 'lib/active_record/acts/uploader_upload.rb', line 201 def width(style = :default) return nil unless self[:width] return self[:width] if style == :default calculate_sizes(style.to_sym) return @image_width.to_i end |