How do I get the raw pre-deserialized value of a model?

Viewed 1543

I have an encrypted type in my model

attribute :name, :encrypted

Which is

class EncryptedType < ActiveRecord::Type::Text

And implements #serialize, #deserialize, and #changed_in_place?.

How can I get the raw value from the database before deserialization?

I want to create a rake task to encrypt values which are in the DB that existed before the fields were encrypted. So before the encryption, the name field contained Bob. After the code change with encryption, reading that value will produce an error (caught), returning an empty string. I want to read the raw value and set it like a normal attribute so it will encrypt it. After the encryption, the field will look like UD8yDrrXYEJXWrZGUGCCQpIAUCjoXCyKOsplsccnkNc=.

I want something like user.name_raw or user.raw_attributes[:name].

2 Answers
Related