12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/manageiq/password/password_mixin.rb', line 12
def encrypt_column(column)
encrypted_columns << column.to_s
mod = generated_methods_for_password_mixin
mod.send(:define_method, column) do
val = send("#{column}_encrypted")
(val.nil? || val.empty?) ? val : MiqPassword.decrypt(val)
end
mod.send(:define_method, "#{column}=") do |val|
val = MiqPassword.try_encrypt(val) unless val.nil? || val.empty?
send("#{column}_encrypted=", val)
end
mod.send(:define_method, "#{column}_encrypted") do
read_attribute(column)
end
mod.send(:define_method, "#{column}_encrypted=") do |val|
write_attribute(column, val)
end
end
|