mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-05 14:28:42 +00:00
24 lines
724 B
Ruby
24 lines
724 B
Ruby
|
|
module Encryptable
|
||
|
|
extend ActiveSupport::Concern
|
||
|
|
|
||
|
|
class_methods do
|
||
|
|
def attr_encrypted(*attributes)
|
||
|
|
attributes.each do |attribute|
|
||
|
|
define_method("#{attribute}=".to_sym) do |value|
|
||
|
|
return if value.nil?
|
||
|
|
|
||
|
|
self.public_send(
|
||
|
|
"encrypted_#{attribute}=".to_sym,
|
||
|
|
EncryptionService.encrypt(value)
|
||
|
|
)
|
||
|
|
end
|
||
|
|
|
||
|
|
define_method(attribute) do
|
||
|
|
value = self.public_send("encrypted_#{attribute}".to_sym)
|
||
|
|
EncryptionService.decrypt(value) if value.present?
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|