Sha256: e32d51735eddf623c0a0025e6489bc3676f035cf75fd81afa584a5cd135005e4

Contents?: true

Size: 891 Bytes

Versions: 7

Compression:

Stored size: 891 Bytes

Contents

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

        included do
          validate :check_attachment_content_type

          has_one_attached :attachment

          default_scope { includes(attachment_attachment: :blob) }

          def self.styles
            @styles ||= {
              mini: '32x32>',
              normal: '128x128>'
            }
          end

          def default_style
            :mini
          end

          def accepted_image_types
            %w(image/jpeg image/jpg image/png image/gif)
          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

7 entries across 7 versions & 1 rubygems

Version Path
spree_core-4.3.3 app/models/spree/taxon_image/configuration/active_storage.rb
spree_core-4.3.2 app/models/spree/taxon_image/configuration/active_storage.rb
spree_core-4.3.1 app/models/spree/taxon_image/configuration/active_storage.rb
spree_core-4.3.0 app/models/spree/taxon_image/configuration/active_storage.rb
spree_core-4.3.0.rc3 app/models/spree/taxon_image/configuration/active_storage.rb
spree_core-4.3.0.rc2 app/models/spree/taxon_image/configuration/active_storage.rb
spree_core-4.3.0.rc1 app/models/spree/taxon_image/configuration/active_storage.rb