Sha256: 85e6cb3ea52ada698017400b05e6207a68afaa7e96dafe5262084451ab1315ee

Contents?: true

Size: 703 Bytes

Versions: 4

Compression:

Stored size: 703 Bytes

Contents

class Asset < ApplicationRecord
  include Concerns::Taggable

  mount_uploader :filename, AssetUploader

  has_many :images, dependent: :destroy

  scope :image, -> { where(content_type: %w(image/gif image/jpeg image/png)) }

  before_save :update_filesize, :update_content_type

  validates :filename, presence: true

  def image?
    content_type.to_s.include?('image')
  end

  def image
    Udongo::Assets::Resizer.new(self) if image?
  end

  def actual_filename
    read_attribute(:filename)
  end

  def deletable?
    images.empty?
  end

  private

  def update_filesize
    self.filesize = filename.size
  end

  def update_content_type
    self.content_type = filename.content_type
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
udongo-5.7.0 app/models/asset.rb
udongo-5.6.0 app/models/asset.rb
udongo-5.5.0 app/models/asset.rb
udongo-5.4.0 app/models/asset.rb