<commit_before>require 'active_model'

module Caprese
  module Record
    class Errors < ActiveModel::Errors
      # Adds an error object for a field, with a code, to the messages hash
      #
      # @param [Symbol] attribute the attribute of the model that this error applies to
      # @param [Symbol] code the error code for the attribute
      # @option [Exception,Boolean] strict raise an exception when creating an error
      #  if Exception, raises that exception
      #  if Boolean `true`, raises ActiveModel::StrictValidationFailed
      # @option [Hash] t interpolation variables to add into the translated full message
      def add(attribute, code = :invalid, options = {})
        options = options.dup
        options[:t] ||= {}
        options[:t][:count] = options[:count]
        options[:t][:value] ||= options[:value] ||
          if attribute != :base && @base.respond_to?(attribute)
            @base.send(:read_attribute_for_validation, attribute)
          else
            nil
          end

        e = Error.new(
          model: @base.class.name.underscore.downcase,
          field: attribute == :base ? nil : attribute,
          code: code,
          t: options[:t]
        )

        if (exception = options[:strict])
          exception = ActiveModel::StrictValidationFailed if exception == true
          raise exception, e.full_message
        end

        self[attribute] << e
      end<commit_msg>Fix I18n error pluralization, Previously, if an error was created using `errors.add :foo, t: { count: 123 }`, the `t[:count]` parameter was internally overwritten the `count` parameter, even if it's unset. This is not backwards compatible. Fix it so that this only happens if no `t[:count]` is provided in the call.<commit_after>require 'active_model'

module Caprese
  module Record
    class Errors < ActiveModel::Errors
      # Adds an error object for a field, with a code, to the messages hash
      #
      # @param [Symbol] attribute the attribute of the model that this error applies to
      # @param [Symbol] code the error code for the attribute
      # @option [Exception,Boolean] strict raise an exception when creating an error
      #  if Exception, raises that exception
      #  if Boolean `true`, raises ActiveModel::StrictValidationFailed
      # @option [Hash] t interpolation variables to add into the translated full message
      def add(attribute, code = :invalid, options = {})
        options = options.dup
        options[:t] ||= {}
        options[:t][:count] ||= options[:count]
        options[:t][:value] ||= options[:value] ||
          if attribute != :base && @base.respond_to?(attribute)
            @base.send(:read_attribute_for_validation, attribute)
          else
            nil
          end

        e = Error.new(
          model: @base.class.name.underscore.downcase,
          field: attribute == :base ? nil : attribute,
          code: code,
          t: options[:t]
        )

        if (exception = options[:strict])
          exception = ActiveModel::StrictValidationFailed if exception == true
          raise exception, e.full_message
        end

        self[attribute] << e
      end
{'fraction_non_alphanumeric': 0.09603274559193954, 'fraction_numerical': 0.0015743073047858943, 'mean_word_length': 2.5418060200668897, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2333966', 'n_tokens_mistral': 823, 'n_tokens_neox': 808, 'n_words': 299}