3
4
5
6
7
8
9
10
11
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/lockbox/calculations.rb', line 3
def pluck(*column_names)
return super unless model.respond_to?(:lockbox_attributes)
lockbox_columns = column_names.map.with_index do |c, i|
next unless c.respond_to?(:to_sym)
[model.lockbox_attributes[c.to_sym], i]
end.select do |la, _i|
la && !la[:migrating]
end
return super unless lockbox_columns.any?
lockbox_columns.each do |la, i|
column_names[i] = la[:encrypted_attribute]
end
result = super(*column_names)
if column_names.size == 1
la = lockbox_columns.first.first
result.map! { |v| model.send("decrypt_#{la[:encrypted_attribute]}", v) }
else
lockbox_columns.each do |la, i|
result.each do |v|
v[i] = model.send("decrypt_#{la[:encrypted_attribute]}", v[i])
end
end
end
result
end
|