Class: Upload

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
AnotherUploader::Icons, AnotherUploader::ImageProcessing, AnotherUploader::MimeTypeGetters, AnotherUploader::Transliteration, Paperclip::Glue, UploadBehavior
Defined in:
app/models/upload.rb

Constant Summary

Constants included from AnotherUploader::MimeTypeGetters

AnotherUploader::MimeTypeGetters::MTG

Constants included from UploadBehavior

UploadBehavior::MTG

Instance Method Summary collapse

Methods included from AnotherUploader::Transliteration

#transliterate, #transliterate_file_name

Methods included from AnotherUploader::MimeTypeGetters

#is_excel?, #is_image?, #is_mp3?, #is_of_type?, #is_pdf?, #is_text?, #is_word?

Methods included from AnotherUploader::ImageProcessing

#calculate_sizes, #dimension, #image_ratio, #max_dimension

Methods included from AnotherUploader::Icons

#icon_name, #icon_path

Instance Method Details

#can_edit?(user) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/upload.rb', line 85

def can_edit?(user)
  !user.blank? && user == self.creator
end

#content_typeObject



53
# File 'app/models/upload.rb', line 53

def content_type;	file_attribute(:content_type);	end

#display_nameObject

@TODO: unit test



81
82
83
# File 'app/models/upload.rb', line 81

def display_name
  CGI::escapeHTML(self.file_name)
end

#exists_locally?Boolean

Returns:

  • (Boolean)


48
# File 'app/models/upload.rb', line 48

def exists_locally?;	local.exists?;	end

#exists_remotely?Boolean

Returns:

  • (Boolean)


49
# File 'app/models/upload.rb', line 49

def exists_remotely?;	remote.exists?;	end

#fileObject



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_nameObject



52
# File 'app/models/upload.rb', line 52

def file_name;	file_attribute(:file_name);	end

#file_sizeObject



54
# File 'app/models/upload.rb', line 54

def file_size;	file_attribute(:file_size);	end

#fingerprintObject



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

#iconObject



72
73
74
# File 'app/models/upload.rb', line 72

def icon
  self.is_image? ? self.file.url(:icon) : icon_path
end

#send_to_remoteObject

Raises:

  • (Paperclip::Error)


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

#thumbObject



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