Sha256: 33d12cc46dbba528c14a34b9a923f4904530eaa30f6441760b85a78ec32424cb

Contents?: true

Size: 551 Bytes

Versions: 4

Compression:

Stored size: 551 Bytes

Contents

# Add an ActiveModel Validator
#
# Example:
#  class MyModel < ActiveRecord::Base
#    validates :encrypted_ssn, :symmetric_encrypted => true
#  end
#
#  m = MyModel.new
#  m.valid?
#  #  => false
#  m.encrypted_ssn = Symmetric::Encryption.encrypt('123456789')
#  m.valid?
#  #  => true
class SymmetricEncryptedValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    record.errors.add(attribute, "must be a value encrypted using Symmetric::Encryption.encrypt") unless Symmetric::Encryption.encrypted?(value)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
symmetric-encryption-0.4.0 lib/symmetric/railties/symmetric_encrypted_validator.rb
symmetric-encryption-0.3.1 lib/symmetric/railties/symmetric_encrypted_validator.rb
symmetric-encryption-0.3.0 lib/symmetric/railties/symmetric_encrypted_validator.rb
symmetric-encryption-0.2.0 lib/symmetric/railties/symmetric_encrypted_validator.rb