Sha256: 6d1c8dad1358904767e14cf4fd3bf778cab621703514f132dd14149f25bc5689

Contents?: true

Size: 568 Bytes

Versions: 9

Compression:

Stored size: 568 Bytes

Contents

# Add an ActiveModel Validator
#
# Example:
#  class MyModel < ActiveRecord::Base
#    validates :encrypted_ssn, symmetric_encryption: true
#  end
#
#  m = MyModel.new
#  m.valid?
#  #  => false
#  m.encrypted_ssn = SymmetricEncryption.encrypt('123456789')
#  m.valid?
#  #  => true
class SymmetricEncryptionValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    return if value.blank? || SymmetricEncryption.encrypted?(value)

    record.errors.add(attribute, 'must be a value encrypted using SymmetricEncryption.encrypt')
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
symmetric-encryption-4.3.1 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.3.0 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.2.1 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.2.0 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.1.4 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.1.3 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.1.2 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.1.1 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.1.0 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb