Sha256: ae2c551433a323c153ccbd64b9cfe0b3b4efd1c0a1190c1fb19e12c7f31cdd52

Contents?: true

Size: 639 Bytes

Versions: 2

Compression:

Stored size: 639 Bytes

Contents

require "active_record"

module AttrKeyring
  module ActiveRecord
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
attr_keyring-0.5.2 lib/attr_keyring/active_record.rb
attr_keyring-0.5.1 lib/attr_keyring/active_record.rb