Sha256: 48facf69cfd9fba5e0f7b08dd4956e2dc239ac4f705dc3819825e383c5377fb6

Contents?: true

Size: 1.09 KB

Versions: 15

Compression:

Stored size: 1.09 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?
              errors.add(:attachment, :attachment_must_be_present)
            end
          end

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spree_core-4.0.9 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.8 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.7.1 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.7 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.6 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.5 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.4 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.3 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.2 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.1 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.0 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.0.rc3 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.0.rc2 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.0.rc1 app/models/spree/image/configuration/active_storage.rb
spree_core-4.0.0.beta app/models/spree/image/configuration/active_storage.rb