Sha256: 562690e2799378c4aec227fcf3d322b256c14e1d84e75551fd36a76aa2a8fabf

Contents?: true

Size: 1.15 KB

Versions: 7

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

7 entries across 7 versions & 1 rubygems

Version Path
spree_core-3.6.6 app/models/spree/image/configuration/active_storage.rb
spree_core-3.6.5 app/models/spree/image/configuration/active_storage.rb
spree_core-3.6.4 app/models/spree/image/configuration/active_storage.rb
spree_core-3.6.3 app/models/spree/image/configuration/active_storage.rb
spree_core-3.6.2 app/models/spree/image/configuration/active_storage.rb
spree_core-3.6.1 app/models/spree/image/configuration/active_storage.rb
spree_core-3.6.0 app/models/spree/image/configuration/active_storage.rb