Module: EncryptionMigrator

Defined in:
lib/encryption_migrator.rb,
lib/encryption_migrator/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.constant_for(model) ⇒ Object



4
5
6
# 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) ⇒ Object



14
15
16
17
18
19
# 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) ⇒ Object



8
9
10
11
12
# 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) ⇒ Object



21
22
23
# File 'lib/encryption_migrator.rb', line 21

def self.encrypted_column_sym(column)
  :"encrypted_#{column}"
end