BigW Consortium Gitlab

attachment_uploader.rb 586 Bytes
Newer Older
gitlabhq committed
1 2 3 4 5 6
# encoding: utf-8

class AttachmentUploader < CarrierWave::Uploader::Base
  storage :file

  def store_dir
7
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
gitlabhq committed
8 9
  end

10
  def image?
11
    img_ext = %w(png jpg jpeg gif bmp tiff)
12
    if file.respond_to?(:extension)
13
      img_ext.include?(file.extension.downcase)
14 15
    else
      # Not all CarrierWave storages respond to :extension
16
      ext = file.path.split('.').last.downcase
17 18 19 20
      img_ext.include?(ext)
    end
  rescue
    false
21
  end
22

23 24
  def file_storage?
    self.class.storage == CarrierWave::Storage::File
25
  end
gitlabhq committed
26
end