<commit_before># frozen_string_literal: true

module Spree
  class Image < Asset
    SIZES = {
      mini: { resize_to_fill: [48, 48] },
      small: { resize_to_fill: [227, 227] },
      product: { resize_to_limit: [240, 240] },
      large: { resize_to_limit: [600, 600] },
    }.freeze

    self.ignored_columns = %i(attachment_file_name
                              attachment_content_type
                              attachment_file_size
                              attachment_updated_at)

    has_one_attached :attachment

    validates :attachment, attached: true, content_type: %r{\Aimage/(png|jpeg|gif|jpg|svg\+xml|webp)\Z}
    validate :no_attachment_errors

    def variant(name)
      if attachment.variable?
        attachment.variant(SIZES[name])
      else
        attachment
      end
    end

    def url(size)
      return unless attachment.attached?

      Rails.application.routes.url_helpers.url_for(variant(size))
    end

    # if there are errors from the plugin, then add a more meaningful message
    def no_attachment_errors
      return if errors[:attachment].empty?

      if errors.all? { |e| e.type == :content_type_invalid }
        attachment.errors.clear
        errors.add :base, I18n.t('spree.admin.products.image_upload_error')
      end<commit_msg>9726 Add attachment_width and attachment_height to the list of ignored columns for spree images<commit_after># frozen_string_literal: true

module Spree
  class Image < Asset
    SIZES = {
      mini: { resize_to_fill: [48, 48] },
      small: { resize_to_fill: [227, 227] },
      product: { resize_to_limit: [240, 240] },
      large: { resize_to_limit: [600, 600] },
    }.freeze

    self.ignored_columns = %i(attachment_file_name
                              attachment_content_type
                              attachment_file_size
                              attachment_updated_at
                              attachment_width
                              attachment_height)

    has_one_attached :attachment

    validates :attachment, attached: true, content_type: %r{\Aimage/(png|jpeg|gif|jpg|svg\+xml|webp)\Z}
    validate :no_attachment_errors

    def variant(name)
      if attachment.variable?
        attachment.variant(SIZES[name])
      else
        attachment
      end
    end

    def url(size)
      return unless attachment.attached?

      Rails.application.routes.url_helpers.url_for(variant(size))
    end

    # if there are errors from the plugin, then add a more meaningful message
    def no_attachment_errors
      return if errors[:attachment].empty?

      if errors.all? { |e| e.type == :content_type_invalid }
        attachment.errors.clear
        errors.add :base, I18n.t('spree.admin.products.image_upload_error')
      end
{'fraction_non_alphanumeric': 0.08698803914461761, 'fraction_numerical': 0.018847408481333816, 'mean_word_length': 2.3333333333333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2817839', 'n_tokens_mistral': 858, 'n_tokens_neox': 791, 'n_words': 184}