Class: ResourceUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::MiniMagick
Defined in:
app/uploaders/resource_uploader.rb

Instance Method Summary collapse

Instance Method Details

#check_content_type!(new_file) ⇒ Object



59
60
61
62
63
64
65
66
# File 'app/uploaders/resource_uploader.rb', line 59

def check_content_type!(new_file)
  return unless image? new_file

  detected_type = file_content_content_type(new_file)
  if detected_type != new_file.content_type
    raise CarrierWave::IntegrityError, "has MIME type mismatch"
  end
end

#content_type_allowlistObject



12
13
14
# File 'app/uploaders/resource_uploader.rb', line 12

def content_type_allowlist
  [%r{image/}, %r{audio/}, %r{video/}, "text/plain"]
end

#dynamic_resize_to_fit(size) ⇒ Object



32
33
34
35
36
# File 'app/uploaders/resource_uploader.rb', line 32

def dynamic_resize_to_fit(size)
  resize_setting = model.blog.send(:"image_#{size}_size").to_i

  resize_to_fit(resize_setting, resize_setting)
end

#fix_exif_rotationObject



46
47
48
49
50
51
52
# File 'app/uploaders/resource_uploader.rb', line 46

def fix_exif_rotation
  manipulate! do |img|
    img.auto_orient
    img = yield(img) if block_given?
    img
  end
end

#image?(new_file) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'app/uploaders/resource_uploader.rb', line 54

def image?(new_file)
  content_type = new_file.content_type
  content_type&.include?("image")
end

#store_dirObject



16
17
18
# File 'app/uploaders/resource_uploader.rb', line 16

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

#stripObject



38
39
40
41
42
43
44
# File 'app/uploaders/resource_uploader.rb', line 38

def strip
  manipulate! do |img|
    img.strip
    img = yield(img) if block_given?
    img
  end
end