Module: Sequel::Plugins::ColumnEncryption::InstanceMethods

Defined in:
lib/sequel/plugins/column_encryption.rb

Instance Method Summary collapse

Instance Method Details

#reencryptObject

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.


687
688
689
690
691
692
693
694
695
696
697
698
# File 'lib/sequel/plugins/column_encryption.rb', line 687

def reencrypt
  do_save = false

  model.send(:column_encryption_metadata).each do |column, |
    if (value = values[column]) && !value.start_with?(.key_searcher.call)
      do_save = true
      values[column] = .encryptor.call(.decryptor.call(value))
    end
  end

  save if do_save
end