Class: MailAttachmentUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::MimeTypes
Defined in:
lib/generators/mastiff/install/templates/carrierwave/mail_attachment_uploader.rb

Overview

encoding: utf-8

Defined Under Namespace

Classes: MimeIO

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete(filename) ⇒ Object



27
28
29
30
31
# 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

.flushObject



24
25
26
# 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

Instance Method Details

#extension_white_listObject

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



52
53
54
# File 'lib/generators/mastiff/install/templates/carrierwave/mail_attachment_uploader.rb', line 52

def extension_white_list
   %w(csv zip)
end

#filenameObject

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



58
59
60
# File 'lib/generators/mastiff/install/templates/carrierwave/mail_attachment_uploader.rb', line 58

def filename
  original_filename.squish.gsub(" ", "_")
end

#store_dirObject

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



40
41
42
# 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) ⇒ Object



44
45
46
47
# 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