Sha256: 131601c91114db5e01c65e3e7e63b218bd4fbd776245031497ecd8d40ece70df

Contents?: true

Size: 606 Bytes

Versions: 2

Compression:

Stored size: 606 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)
            super

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
attr_keyring-0.5.0 lib/attr_keyring/active_record.rb
attr_keyring-0.4.0 lib/attr_keyring/active_record.rb