Class: ResourceUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- ResourceUploader
- Includes:
- CarrierWave::MiniMagick
- Defined in:
- app/uploaders/resource_uploader.rb
Instance Method Summary collapse
- #check_content_type!(new_file) ⇒ Object
- #content_type_allowlist ⇒ Object
- #dynamic_resize_to_fit(size) ⇒ Object
- #image?(new_file) ⇒ Boolean
- #store_dir ⇒ Object
Instance Method Details
#check_content_type!(new_file) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'app/uploaders/resource_uploader.rb', line 40 def check_content_type!(new_file) detected_type = if image? new_file file_content_content_type(new_file) else file_content_type(new_file) end if detected_type != new_file.content_type raise CarrierWave::IntegrityError, "has MIME type mismatch" end end |
#content_type_allowlist ⇒ Object
9 10 11 |
# File 'app/uploaders/resource_uploader.rb', line 9 def content_type_allowlist [%r{image/}, %r{audio/}, %r{video/}, "text/plain"] end |
#dynamic_resize_to_fit(size) ⇒ Object
29 30 31 32 33 |
# File 'app/uploaders/resource_uploader.rb', line 29 def dynamic_resize_to_fit(size) resize_setting = model.blog.send("image_#{size}_size").to_i resize_to_fit(resize_setting, resize_setting) end |
#image?(new_file) ⇒ Boolean
35 36 37 38 |
# File 'app/uploaders/resource_uploader.rb', line 35 def image?(new_file) content_type = new_file.content_type content_type&.include?("image") end |
#store_dir ⇒ Object
13 14 15 |
# File 'app/uploaders/resource_uploader.rb', line 13 def store_dir "files/#{model.class.to_s.underscore}/#{model.id}" end |