module EncryptionMigrator

Constants

VERSION

Public Class Methods

constant_for(model) click to toggle source
# File lib/encryption_migrator.rb, line 4
def self.constant_for(model)
  model.to_s.singularize.camelize.constantize
end
decrypt_and_update_row(row, const, column, key) click to toggle source
# File lib/encryption_migrator.rb, line 14
def self.decrypt_and_update_row(row, const, column, key)
  encrypted_sym = encrypted_column_sym(column)
  define_class_with_encrypted(const, column, encrypted_sym, key)
  attr = const.decrypt(column, row.read_attribute(encrypted_sym))
  row.update_column(:"#{column}", attr)
end
define_class_with_encrypted(const, attr, encrypted_attr, key) click to toggle source
# File lib/encryption_migrator.rb, line 8
def self.define_class_with_encrypted(const, attr, encrypted_attr, key)
  const.class_eval do
    attr_encrypted attr, key: key, attribute: encrypted_attr
  end
end
encrypted_column_sym(column) click to toggle source
# File lib/encryption_migrator.rb, line 21
def self.encrypted_column_sym(column)
  :"encrypted_#{column}"
end