Module: Locomotive::CarrierWave::Uploader::Asset

Extended by:
ActiveSupport::Concern
Included in:
Locomotive::ContentAssetUploader, ThemeAssetUploader
Defined in:
lib/locomotive/carrierwave/asset.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#image?(file) ⇒ Boolean

Returns:



65
66
67
# File 'lib/locomotive/carrierwave/asset.rb', line 65

def image?(file)
  model.image?
end

#set_content_type_of_model(*args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/locomotive/carrierwave/asset.rb', line 34

def set_content_type_of_model(*args)
  value         = :other
  content_type  = file.content_type

  if content_type.blank? || content_type == 'application/octet-stream'
    content_type = File.mime_type?(original_filename)
  end

  self.class.content_types.each_pair do |type, rules|
    rules.each do |rule|
      case rule
      when String then value = type if content_type == rule
      when Regexp then value = type if (content_type =~ rule) == 0
      end
    end
  end

  model.content_type = value
end

#set_size(*args) ⇒ Object



54
55
56
# File 'lib/locomotive/carrierwave/asset.rb', line 54

def set_size(*args)
  model.size = file.size
end

#set_width_and_heightObject



58
59
60
61
62
63
# File 'lib/locomotive/carrierwave/asset.rb', line 58

def set_width_and_height
  if model.image?
    dragonfly_img = Dragonfly.app.fetch_file(current_path)
    model.width, model.height = dragonfly_img.width, dragonfly_img.height
  end
end