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_image_content_type!(new_file) ⇒ Object
- #dynamic_resize_to_fit(size) ⇒ Object
- #image?(new_file) ⇒ Boolean
- #store_dir ⇒ Object
Instance Method Details
#check_image_content_type!(new_file) ⇒ Object
34 35 36 37 38 39 |
# File 'app/uploaders/resource_uploader.rb', line 34 def check_image_content_type!(new_file) if image?(new_file) magic_type = mime_magic_content_type(new_file) raise CarrierWave::IntegrityError, 'has MIME type mismatch' if magic_type != new_file.content_type end end |
#dynamic_resize_to_fit(size) ⇒ Object
23 24 25 26 27 |
# File 'app/uploaders/resource_uploader.rb', line 23 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
29 30 31 32 |
# File 'app/uploaders/resource_uploader.rb', line 29 def image?(new_file) content_type = new_file.content_type content_type && content_type.include?('image') end |
#store_dir ⇒ Object
7 8 9 |
# File 'app/uploaders/resource_uploader.rb', line 7 def store_dir "files/#{model.class.to_s.underscore}/#{model.id}" end |