class MailAttachmentUploader

Public Class Methods

delete(filename) click to toggle source
# File lib/generators/mastiff/install/templates/carrierwave/mail_attachment_uploader.rb, line 27
def self.delete(filename)
  return if filename.blank?
  filepath = File.join(new.store_dir, filename)
  File.delete(filepath) if File.exists?(filepath)
end
flush() click to toggle source
# File lib/generators/mastiff/install/templates/carrierwave/mail_attachment_uploader.rb, line 24
def self.flush
  Dir.glob(File.join(new.store_dir, '*')).each{|f| File.delete(f)}
end

Public Instance Methods

extension_white_list() click to toggle source

Add a white list of extensions which are allowed to be uploaded. For images you might use something like this:

# File lib/generators/mastiff/install/templates/carrierwave/mail_attachment_uploader.rb, line 52
def extension_white_list
   %w(csv zip)
end
filename() click to toggle source

Override the filename of the uploaded files: Avoid using model.id or version_name here, see uploader/store.rb for details.

# File lib/generators/mastiff/install/templates/carrierwave/mail_attachment_uploader.rb, line 58
def filename
  original_filename.squish.gsub(" ", "_")
end
store_dir() click to toggle source

Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:

# File lib/generators/mastiff/install/templates/carrierwave/mail_attachment_uploader.rb, line 40
def store_dir
  Mastiff.attachment_dir
end
store_mime(fname, mime_blob) click to toggle source
# File lib/generators/mastiff/install/templates/carrierwave/mail_attachment_uploader.rb, line 44
def store_mime(fname, mime_blob)
  mime_io = MimeIO.new(fname, mime_blob)
  store!(mime_io)
end