Class: Sunrise::CarrierWave::BaseUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::MiniMagick
Defined in:
lib/sunrise/carrier_wave/base_uploader.rb

Instance Method Summary collapse

Instance Method Details

#default_urlObject



39
40
41
# File 'lib/sunrise/carrier_wave/base_uploader.rb', line 39

def default_url
  "/images/defaults/#{model.class.to_s.underscore}_#{version_name}.png"
end

#image?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/sunrise/carrier_wave/base_uploader.rb', line 60

def image?
  model.image?
end

#quality(percentage) ⇒ Object

process :quality => 85



31
32
33
34
35
36
37
# File 'lib/sunrise/carrier_wave/base_uploader.rb', line 31

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

#set_content_typeObject



43
44
45
46
47
# File 'lib/sunrise/carrier_wave/base_uploader.rb', line 43

def set_content_type
  type = file.content_type == 'application/octet-stream' || file.content_type.blank? ? MIME::Types.type_for(original_filename).first.to_s : file.content_type
   
  model.data_content_type = type
end

#set_sizeObject



49
50
51
# File 'lib/sunrise/carrier_wave/base_uploader.rb', line 49

def set_size
  model.data_file_size = file.size
end

#set_width_and_heightObject



53
54
55
56
57
58
# File 'lib/sunrise/carrier_wave/base_uploader.rb', line 53

def set_width_and_height
  if model.image? && model.has_dimensions?
    magick = ::MiniMagick::Image.new(current_path)
    model.width, model.height = magick[:width], magick[:height]
  end
end

#store_dirObject

default store assets path



17
18
19
# File 'lib/sunrise/carrier_wave/base_uploader.rb', line 17

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

#stripObject

process :strip



22
23
24
25
26
27
28
# File 'lib/sunrise/carrier_wave/base_uploader.rb', line 22

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