We're trying to use this Gem on a parent model that we can then declare fields at the child model level so we can share the settings for instantiating the encryption.
class EncryptedModel < ApplicationRecord
self.abstract_class = true
after_initialize do
::CryptKeeper::Model::ClassMethods.crypt_keeper encrypted_fields,
encryptor: :active_support,
key: key,
salt: salt
end
private
def encrypted_fields
raise "#{__method__} not implemented in #{self.class.name}"
end
def key
ENV['CRYPT_KEEPER_KEY'] || 'key'
end
def salt
ENV['CRYPT_KEEPER_SALT'] || 'salt'
end
end
class MyModel < EncryptedModel
private
def encrypted_fields
%i[field_one field_two]
end
end
We have to use the after_initialize otherwise the encrypted_fields, key, and salt are undefined... but we now get the error: undefined method 'crypt_keeper' for CryptKeeper::Model::ClassMethods:Module.
If I don't specify the Module.. then it tries to find the crypt_keeper method on the MyModel class which again it doesn't exist...
We're trying to use this Gem on a parent model that we can then declare fields at the child model level so we can share the settings for instantiating the encryption.
We have to use the
after_initialize
otherwise theencrypted_fields
,key
, andsalt
are undefined... but we now get the error:undefined method 'crypt_keeper' for CryptKeeper::Model::ClassMethods:Module
.If I don't specify the Module.. then it tries to find the
crypt_keeper
method on theMyModel
class which again it doesn't exist...