Sha256: 53c7596bd00c24e757bfb2af41870585f5d1a03332ead42810b845c0fe5151f2

Contents?: true

Size: 1.15 KB

Versions: 19

Compression:

Stored size: 1.15 KB

Contents

module Spree
  class Image < Asset
    module Configuration
      module ActiveStorage
        extend ActiveSupport::Concern

        included do
          validate :check_attachment_presence
          validate :check_attachment_content_type

          has_one_attached :attachment

          def self.styles
            @styles ||= {
              mini: '48x48>',
              small: '100x100>',
              product: '240x240>',
              large: '600x600>'
            }
          end

          def default_style
            :product
          end

          def accepted_image_types
            %w(image/jpeg image/jpg image/png image/gif)
          end

          def check_attachment_presence
            unless attachment.attached?
              attachment.purge
              errors.add(:attachment, :attachment_must_be_present)
            end
          end

          def check_attachment_content_type
            if attachment.attached? && !attachment.content_type.in?(accepted_image_types)
              attachment.purge
              errors.add(:attachment, :not_allowed_content_type)
            end
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
spree_core-3.7.14.1 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.14 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.13 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.12 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.11 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.10 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.9 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.8 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.7 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.6 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.5 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.4 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.3 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.2 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.1 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.0 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.0.rc3 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.0.rc2 app/models/spree/image/configuration/active_storage.rb
spree_core-3.7.0.rc1 app/models/spree/image/configuration/active_storage.rb