Class: EncryptionWrapper
- Inherits:
-
Object
- Object
- EncryptionWrapper
- Defined in:
- lib/acts_as_encrypted.rb
Overview
Encryption Wrapper
Use EncryptionWrapper as a callback in a model to encrypt database fields. It is recomended that you don’t use it directly, but instead use:
acts_as_encrypted
encrypt_field :field_one, :field_two, :field_three
Instance Method Summary collapse
- #decrypt_field(record) ⇒ Object (also: #after_save)
- #encrypt_field(record) ⇒ Object (also: #before_save)
-
#initialize(attribute) ⇒ EncryptionWrapper
constructor
A new instance of EncryptionWrapper.
Constructor Details
#initialize(attribute) ⇒ EncryptionWrapper
Returns a new instance of EncryptionWrapper.
107 108 109 110 111 |
# File 'lib/acts_as_encrypted.rb', line 107 def initialize(attribute) @attribute = attribute.to_sym @attribute_safe = (attribute.to_s + '_safe').to_sym @attr_setter = (attribute.to_s + '=').to_sym end |
Instance Method Details
#decrypt_field(record) ⇒ Object Also known as: after_save
117 118 119 |
# File 'lib/acts_as_encrypted.rb', line 117 def decrypt_field(record) record.send(@attr_setter, decrypt(record.send(@attribute_safe))) end |
#encrypt_field(record) ⇒ Object Also known as: before_save
113 114 115 |
# File 'lib/acts_as_encrypted.rb', line 113 def encrypt_field(record) record.send(@attr_setter, encrypt(record.send(@attribute_safe))) end |