Sha256: 84a36090f0bf410c35623f011e29cdfe81904a0bfb3df78a24c4fe1abf4002aa

Contents?: true

Size: 670 Bytes

Versions: 4

Compression:

Stored size: 670 Bytes

Contents

# frozen_string_literal: true

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

4 entries across 4 versions & 1 rubygems

Version Path
attr_keyring-0.6.1 lib/attr_keyring/active_record.rb
attr_keyring-0.6.0 lib/attr_keyring/active_record.rb
attr_keyring-0.5.4 lib/attr_keyring/active_record.rb
attr_keyring-0.5.3 lib/attr_keyring/active_record.rb