ToolJet/lib/encryptable.rb

24 lines
572 B
Ruby
Raw Normal View History

2021-04-15 07:39:45 +00:00
module Encryptable
2021-04-29 06:41:23 +00:00
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?
public_send(
"encrypted_#{attribute}=".to_sym,
EncryptionService.encrypt(value)
)
2021-04-15 07:39:45 +00:00
end
2021-04-29 06:41:23 +00:00
define_method(attribute) do
value = public_send("encrypted_#{attribute}".to_sym)
EncryptionService.decrypt(value) if value.present?
end
end
2021-04-15 07:39:45 +00:00
end
2021-04-29 06:41:23 +00:00
end
2021-04-15 07:39:45 +00:00
end