BigW Consortium Gitlab

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

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

6 7
  after :store, :reset_events_cache

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

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

  def secure_url
26
    Gitlab.config.gitlab.relative_url_root + "/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}"
27 28 29 30
  end

  def file_storage?
    self.class.storage == CarrierWave::Storage::File
31
  end
32 33 34 35

  def reset_events_cache(file)
    model.reset_events_cache if model.is_a?(User)
  end
gitlabhq committed
36
end