Sha256: 66252ac9831777a0de0d91c4cdaf1b91619f9946e92d2e3bc33d4aceb1521ab2

Contents?: true

Size: 544 Bytes

Versions: 8

Compression:

Stored size: 544 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)
    record.errors.add(attribute, 'must be a value encrypted using SymmetricEncryption.encrypt') unless SymmetricEncryption.encrypted?(value)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
symmetric-encryption-4.0.0 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.0.0.beta3 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-3.9.1 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-3.9.0 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-3.8.3 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-3.8.2 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-3.8.1 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-3.8.0 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb