Class: Reencryptor::GlobalToPerAttributeIVSalt::GlobalToPerAttributeEncryption
- Inherits:
-
Object
- Object
- Reencryptor::GlobalToPerAttributeIVSalt::GlobalToPerAttributeEncryption
- Defined in:
- lib/reencryptor/global_to_per_attribute_iv_salt/global_to_per_attribute_encryption.rb
Instance Attribute Summary collapse
-
#classes ⇒ Object
Returns the value of attribute classes.
Instance Method Summary collapse
-
#initialize(classes_hash: {}) ⇒ GlobalToPerAttributeEncryption
constructor
A new instance of GlobalToPerAttributeEncryption.
- #perform ⇒ Object
- #update_class_fields(klass_name, fields) ⇒ Object
- #update_encrypted_field(instance, field) ⇒ Object
- #update_encrypted_object(instance) ⇒ Object
Constructor Details
#initialize(classes_hash: {}) ⇒ GlobalToPerAttributeEncryption
Returns a new instance of GlobalToPerAttributeEncryption.
6 7 8 |
# 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 |
Instance Attribute Details
#classes ⇒ Object
Returns the value of attribute classes.
4 5 6 |
# File 'lib/reencryptor/global_to_per_attribute_iv_salt/global_to_per_attribute_encryption.rb', line 4 def classes @classes end |
Instance Method Details
#perform ⇒ Object
34 35 36 37 38 39 |
# 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) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Object
22 23 24 25 26 27 |
# 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) ⇒ Object
29 30 31 32 |
# 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 |