Sha256: 8f1794ca0d22091eba4764e4f75ced64cc852f011479feb574a8974caab8ecb5
Contents?: true
Size: 1.22 KB
Versions: 10
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true require 'mini_magick' module Spree module ActiveStorageAdapter # Decorares AtiveStorage attachment to add methods exptected by Solidus' # Paperclip-oriented attachment support. class Attachment delegate_missing_to :@attachment DEFAULT_SIZE = '100%' def initialize(attachment, styles: {}) @attachment = attachment @styles = styles end def exists? attached? end def filename blob.filename.to_s end def url(style = nil) variant(style).url end def variant(style = nil) size = style_to_size(style&.to_sym) @attachment.variant( resize: size, strip: true, 'auto-orient': true, colorspace: 'sRGB', ).processed end def height metadata[:height] end def width metadata[:width] end def destroy return false unless attached? purge true end private def metadata analyze unless analyzed? @attachment.metadata end def style_to_size(style) @styles.fetch(style) { DEFAULT_SIZE } end end end end
Version data entries
10 entries across 10 versions & 1 rubygems