Module: ActiveRecord::Encryption::EncryptableRecord
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/active_record/encryption/encryptable_record.rb
Overview
This is the concern mixed in Active Record models to make them encryptable. It adds the encrypts
attribute declaration, as well as the API to encrypt and decrypt records.
Instance Method Summary collapse
-
#ciphertext_for(attribute_name) ⇒ Object
Returns the ciphertext for
attribute_name
. -
#decrypt ⇒ Object
Decrypts all the encryptable attributes and saves the changes.
-
#encrypt ⇒ Object
Encrypts all the encryptable attributes and saves the changes.
-
#encrypted_attribute?(attribute_name) ⇒ Boolean
Returns whether a given attribute is encrypted or not.
Instance Method Details
#ciphertext_for(attribute_name) ⇒ Object
Returns the ciphertext for attribute_name
.
148 149 150 |
# File 'lib/active_record/encryption/encryptable_record.rb', line 148 def ciphertext_for(attribute_name) read_attribute_before_type_cast(attribute_name) end |
#decrypt ⇒ Object
Decrypts all the encryptable attributes and saves the changes.
158 159 160 |
# File 'lib/active_record/encryption/encryptable_record.rb', line 158 def decrypt decrypt_attributes if has_encrypted_attributes? end |
#encrypt ⇒ Object
Encrypts all the encryptable attributes and saves the changes.
153 154 155 |
# File 'lib/active_record/encryption/encryptable_record.rb', line 153 def encrypt encrypt_attributes if has_encrypted_attributes? end |
#encrypted_attribute?(attribute_name) ⇒ Boolean
Returns whether a given attribute is encrypted or not.
143 144 145 |
# File 'lib/active_record/encryption/encryptable_record.rb', line 143 def encrypted_attribute?(attribute_name) ActiveRecord::Encryption.encryptor.encrypted? ciphertext_for(attribute_name) end |