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.



708
709
710
711
712
713
714
715
716
717
718
719
# File 'lib/sequel/plugins/column_encryption.rb', line 708

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