module Sequel::Plugins::ColumnEncryption::InstanceMethods

  1. lib/sequel/plugins/column_encryption.rb

Methods

Public Instance

  1. reencrypt

Public Instance methods

reencrypt()

Reencrypt the model if needed. Looks at all of the models encrypted columns and if any were encypted with older keys or a different format, reencrypt with the current key and format and save the object. Returns the object if reencryption was needed, or nil if reencryption was not needed.

[show source]
    # File lib/sequel/plugins/column_encryption.rb
687 def reencrypt
688   do_save = false
689 
690   model.send(:column_encryption_metadata).each do |column, metadata|
691     if (value = values[column]) && !value.start_with?(metadata.key_searcher.call)
692       do_save = true
693       values[column] = metadata.encryptor.call(metadata.decryptor.call(value))
694     end
695   end
696 
697   save if do_save
698 end