Sha256: 13c6edd5c3a6e28a7580f1a368a89bf9302959958f5940684c4844ccbb4520fb

Contents?: true

Size: 884 Bytes

Versions: 35

Compression:

Stored size: 884 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  module Encryption
    module ExtendedDeterministicUniquenessValidator
      def self.install_support
        ActiveRecord::Validations::UniquenessValidator.prepend(EncryptedUniquenessValidator)
      end

      module EncryptedUniquenessValidator
        def validate_each(record, attribute, value)
          super(record, attribute, value)

          klass = record.class
          if klass.deterministic_encrypted_attributes&.include?(attribute)
            encrypted_type = klass.type_for_attribute(attribute)
            encrypted_type.previous_types.each do |type|
              encrypted_value = type.serialize(value)
              ActiveRecord::Encryption.without_encryption do
                super(record, attribute, encrypted_value)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 4 rubygems

Version Path
activerecord-8.0.0 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-7.2.2 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-7.1.5 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-8.0.0.rc2 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-7.2.1.2 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-7.1.4.2 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-8.0.0.rc1 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-7.2.1.1 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-7.1.4.1 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-8.0.0.beta1 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
omg-activerecord-8.0.0.alpha9 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
omg-activerecord-8.0.0.alpha8 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
omg-activerecord-8.0.0.alpha7 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
omg-activerecord-8.0.0.alpha4 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
omg-activerecord-8.0.0.alpha3 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
omg-activerecord-8.0.0.alpha2 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
omg-activerecord-8.0.0.alpha1 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-7.1.4 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-7.2.1 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb
activerecord-7.2.0 lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb