Sha256: 84bfdf776654747d61b00e2a2441ecb456962be6178ef528349b5f2b030aa456

Contents?: true

Size: 813 Bytes

Versions: 18

Compression:

Stored size: 813 Bytes

Contents

# frozen_string_literal: true

module Spree::Image::ActiveStorageAttachment
  extend ActiveSupport::Concern
  include Spree::ActiveStorageAdapter

  delegate :width, :height, to: :attachment, prefix: true

  included do
    validates :attachment, presence: true
    validate :attachment_is_an_image
    validate :supported_content_type

    has_attachment :attachment,
                   styles: {
                   mini: '48x48>',
                   small: '400x400>',
                   product: '680x680>',
                   large: '1200x1200>'
                 },
                 default_style: :product

    def supported_content_type
      unless attachment.content_type.in?(Spree::Config.allowed_image_mime_types)
        errors.add(:attachment, :content_type_not_supported)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
solidus_core-3.0.8 app/models/spree/image/active_storage_attachment.rb
solidus_core-3.0.7 app/models/spree/image/active_storage_attachment.rb
solidus_core-2.11.17 app/models/spree/image/active_storage_attachment.rb
solidus_core-2.11.16 app/models/spree/image/active_storage_attachment.rb
solidus_core-3.0.6 app/models/spree/image/active_storage_attachment.rb
solidus_core-2.11.15 app/models/spree/image/active_storage_attachment.rb
solidus_core-2.11.14 app/models/spree/image/active_storage_attachment.rb
solidus_core-3.0.5 app/models/spree/image/active_storage_attachment.rb
solidus_core-2.11.13 app/models/spree/image/active_storage_attachment.rb
solidus_core-3.0.4 app/models/spree/image/active_storage_attachment.rb
solidus_core-2.11.12 app/models/spree/image/active_storage_attachment.rb
solidus_core-3.0.3 app/models/spree/image/active_storage_attachment.rb
solidus_core-2.11.11 app/models/spree/image/active_storage_attachment.rb
solidus_core-3.0.2 app/models/spree/image/active_storage_attachment.rb
solidus_core-2.11.10 app/models/spree/image/active_storage_attachment.rb
solidus_core-3.0.1 app/models/spree/image/active_storage_attachment.rb
solidus_core-3.0.0 app/models/spree/image/active_storage_attachment.rb
solidus_core-2.11.9 app/models/spree/image/active_storage_attachment.rb