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

#apply_content_type_exception(value) ⇒ Object



80
81
82
83
# File 'lib/locomotive/carrierwave/asset.rb', line 80

def apply_content_type_exception(value)
  # by default, do nothing
  value
end

#find_content_type_of_model(content_type) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/locomotive/carrierwave/asset.rb', line 65

def find_content_type_of_model(content_type)
  value = :other

  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

  apply_content_type_exception(value)
end

#image?(file) ⇒ Boolean

Returns:



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

def image?(file)
  model.image?
end

#set_content_type_of_model(*args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/locomotive/carrierwave/asset.rb', line 34

def set_content_type_of_model(*args)
  content_type  = file.content_type

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

  value = find_content_type_of_model(content_type)

  model.content_type = value
end

#set_size(*args) ⇒ Object



46
47
48
# File 'lib/locomotive/carrierwave/asset.rb', line 46

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

#set_width_and_heightObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/locomotive/carrierwave/asset.rb', line 50

def set_width_and_height
  if model.image?
    dragonfly_img = ::Dragonfly.app(:engine).fetch_file(current_path)
    begin
      model.width, model.height = dragonfly_img.width, dragonfly_img.height
    rescue Exception => e
      Rails.logger.error "[Dragonfly] Unable to get the width and the height, error: #{e.message}\n#{e.backtrace.join("\n")}"
    end
  end
end