class Reencryptor::GlobalToPerAttributeIVSalt::GlobalToPerAttributeEncryption
Attributes
classes[RW]
Public Class Methods
new(classes_hash: {})
click to toggle source
# File lib/reencryptor/global_to_per_attribute_iv_salt/global_to_per_attribute_encryption.rb, line 6 def initialize(classes_hash: {}) self.classes = classes_hash end
Public Instance Methods
perform()
click to toggle source
# File lib/reencryptor/global_to_per_attribute_iv_salt/global_to_per_attribute_encryption.rb, line 34 def perform self.classes.each do |klass, fields| load "#{klass.to_s.underscore}.rb" self.update_class_fields(klass.to_s, fields) end end
update_class_fields(klass_name, fields)
click to toggle source
# File lib/reencryptor/global_to_per_attribute_iv_salt/global_to_per_attribute_encryption.rb, line 10 def update_class_fields(klass_name, fields) klass = klass_name.camelize.constantize puts "Starting #{klass.to_s}" ActiveRecord::Base.transaction do klass.all.each do | instance | fields.each do |f| self.update_encrypted_field(instance, f) end end end end
update_encrypted_field(instance, field)
click to toggle source
# File lib/reencryptor/global_to_per_attribute_iv_salt/global_to_per_attribute_encryption.rb, line 22 def update_encrypted_field(instance, field) instance.send("#{field}=", instance.send("#{field}_old")) instance.update_column("encrypted_#{field}", instance.send("encrypted_#{field}")) instance.update_column("encrypted_#{field}_iv", instance.send("encrypted_#{field}_iv")) instance.update_column("encrypted_#{field}_salt", instance.send("encrypted_#{field}_salt")) end
update_encrypted_object(instance)
click to toggle source
# File lib/reencryptor/global_to_per_attribute_iv_salt/global_to_per_attribute_encryption.rb, line 29 def update_encrypted_object(instance) fields = self.classes[instance.class.name.to_sym] fields.each {|f| self.update_encrypted_field(instance, f)} end