Sha256: 459ffeaa2cf224b8050f03a1d7d317572a0100ef3b2a05faf5e9bfb32559d3d7
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
require "acts_as_encryptable/version" module ActsAsEncryptable def acts_as_encryptable column_name, key, salt send :define_method, column_name do encryptor = "@encryptor_#{key}_#{salt}" instance_variable_set( encryptor, ActiveSupport::MessageEncryptor.new( ActiveSupport::KeyGenerator.new(send key).generate_key(send salt) ) ) unless instance_variable_defined? encryptor encryptor = instance_variable_get(encryptor) encryptor.decrypt_and_verify(read_attribute column_name) end send :define_method, "#{column_name}=".to_sym do |value| encryptor = "@encryptor_#{key}_#{salt}" instance_variable_set( encryptor, ActiveSupport::MessageEncryptor.new( ActiveSupport::KeyGenerator.new(send key).generate_key(send salt) ) ) unless instance_variable_defined? encryptor encryptor = instance_variable_get(encryptor) write_attribute column_name, encryptor.encrypt_and_sign(value) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts_as_encryptable-0.1.0 | lib/acts_as_encryptable.rb |