Module: AttrKeyring::ActiveRecord

Defined in:
lib/attr_keyring/active_record.rb

Class Method Summary collapse

Class Method Details

.included(target) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/attr_keyring/active_record.rb', line 7

def self.included(target)
  AttrKeyring.setup(target)

  target.class_eval do
    before_save :migrate_to_latest_encryption_key

    def keyring_rotate!
      migrate_to_latest_encryption_key
      save!
    end
  end

  target.prepend(
    Module.new do
      def reload(options = nil)
        instance = super

        self.class.encrypted_attributes.each do |attribute|
          clear_decrypted_column_cache(attribute)
        end

        instance
      end
    end
  )
end