<commit_before># frozen_string_literal: true

module ActiveRecord
  module Encryption
    # An +ActiveModel::Type+ that encrypts/decrypts strings of text
    #
    # This is the central piece that connects the encryption system with +encrypts+ declarations in the
    # model classes. Whenever you declare an attribute as encrypted, it configures an +EncryptedAttributeType+
    # for that attribute.
    class EncryptedAttributeType < ::ActiveRecord::Type::Text
      include ActiveModel::Type::Helpers::Mutable

      attr_reader :key_provider, :previous_types, :subtype, :downcase

      def initialize(key_provider: nil, deterministic: false, downcase: false, subtype: ActiveModel::Type::String.new, previous_types: [], **context_properties)
        super()
        @key_provider = key_provider
        @deterministic = deterministic
        @downcase = downcase
        @subtype = subtype
        @previous_types = previous_types
        @context_properties = context_properties
      end

      def deserialize(value)
        @subtype.deserialize decrypt(value)
      end

      def serialize(value)
        casted_value = @subtype.serialize(value)
        casted_value = casted_value&.downcase if @downcase
        encrypt(casted_value.to_s) unless casted_value.nil? # Object values without a proper serializer get converted with #to_s
      end

      def changed_in_place?(raw_old_value, new_value)
        old_value = raw_old_value.nil? ? nil : deserialize(raw_old_value)
        old_value != new_value
      end

      def deterministic?
        @deterministic
      end

      def additional_encrypted_types # :nodoc:
        @additional_encrypted_types ||= if support_unencrypted_data?
          previous_types.including(clean_text_type)
        else
          previous_types
        end
      end<commit_msg>Fix: memoization that was making tests fail<commit_after># frozen_string_literal: true

module ActiveRecord
  module Encryption
    # An +ActiveModel::Type+ that encrypts/decrypts strings of text
    #
    # This is the central piece that connects the encryption system with +encrypts+ declarations in the
    # model classes. Whenever you declare an attribute as encrypted, it configures an +EncryptedAttributeType+
    # for that attribute.
    class EncryptedAttributeType < ::ActiveRecord::Type::Text
      include ActiveModel::Type::Helpers::Mutable

      attr_reader :key_provider, :previous_types, :subtype, :downcase

      def initialize(key_provider: nil, deterministic: false, downcase: false, subtype: ActiveModel::Type::String.new, previous_types: [], **context_properties)
        super()
        @key_provider = key_provider
        @deterministic = deterministic
        @downcase = downcase
        @subtype = subtype
        @previous_types = previous_types
        @context_properties = context_properties
      end

      def deserialize(value)
        @subtype.deserialize decrypt(value)
      end

      def serialize(value)
        casted_value = @subtype.serialize(value)
        casted_value = casted_value&.downcase if @downcase
        encrypt(casted_value.to_s) unless casted_value.nil? # Object values without a proper serializer get converted with #to_s
      end

      def changed_in_place?(raw_old_value, new_value)
        old_value = raw_old_value.nil? ? nil : deserialize(raw_old_value)
        old_value != new_value
      end

      def deterministic?
        @deterministic
      end

      def additional_encrypted_types # :nodoc:
        if support_unencrypted_data?
          @previous_types_with_clean_text_type ||= previous_types.including(clean_text_type)
        else
          previous_types
        end
      end
{'fraction_non_alphanumeric': 0.06923703502579419, 'fraction_numerical': 0.0, 'mean_word_length': 3.172140430351076, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7151505', 'n_tokens_mistral': 1031, 'n_tokens_neox': 997, 'n_words': 269}