Sha256: 09e248666c7dfa7acde04fe9f0fd798c7eb9ec34ef9d17e94e715b39c8165de4

Contents?: true

Size: 568 Bytes

Versions: 5

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

5 entries across 5 versions & 1 rubygems

Version Path
symmetric-encryption-4.6.0 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.5.0 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.4.0 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.3.3 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb
symmetric-encryption-4.3.2 lib/symmetric_encryption/railties/symmetric_encryption_validator.rb