Sha256: 6ae8c600fc73ec8ec98c9e53fb7fc27ca14f09f7155a2324f7401391134a81ff

Contents?: true

Size: 824 Bytes

Versions: 7

Compression:

Stored size: 824 Bytes

Contents

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

        included do
          validate :check_attachment_content_type

          has_one_attached :attachment

          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-3.6.6 app/models/spree/taxon_icon/configuration/active_storage.rb
spree_core-3.6.5 app/models/spree/taxon_icon/configuration/active_storage.rb
spree_core-3.6.4 app/models/spree/taxon_icon/configuration/active_storage.rb
spree_core-3.6.3 app/models/spree/taxon_icon/configuration/active_storage.rb
spree_core-3.6.2 app/models/spree/taxon_icon/configuration/active_storage.rb
spree_core-3.6.1 app/models/spree/taxon_icon/configuration/active_storage.rb
spree_core-3.6.0 app/models/spree/taxon_icon/configuration/active_storage.rb