Class: SymmetricEncryptionValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/symmetric_encryption/railties/symmetric_encryption_validator.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


15
16
17
# File 'lib/symmetric_encryption/railties/symmetric_encryption_validator.rb', line 15

def validate_each(record, attribute, value)
  record.errors.add(attribute, "must be a value encrypted using SymmetricEncryption.encrypt") unless SymmetricEncryption.encrypted?(value)
end