summaryrefslogtreecommitdiff
path: root/app/uploaders/avatar_uploader.rb
blob: 2c72df44ff0ba10ffb9ab4daed36a9212fe950ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# encoding: utf-8

class AvatarUploader < CarrierWave::Uploader::Base
  include UploaderHelper
  include CarrierWave::MiniMagick

  storage :file

  after :store, :reset_events_cache

  process :cropper

  def cropper
    return unless model.respond_to?(:avatar_crop_size) && model.valid?

    manipulate! do |img|
      img.crop "#{model.avatar_crop_size}x#{model.avatar_crop_size}+#{model.avatar_crop_x}+#{model.avatar_crop_y}"
    end
  end

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

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