Sha256: 9e6d87cb477845db7735cd688f404f073677c0ca86389c30e47e23aef1084d9b

Contents?: true

Size: 567 Bytes

Versions: 2

Compression:

Stored size: 567 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

2 entries across 2 versions & 1 rubygems

Version Path
symmetric-encryption-4.1.0.beta1 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.0.1 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb