module Slosilo::Migration::EncryptedAttributes::ClassMethods

Public Instance Methods

attr_encrypted(*a) click to toggle source
Calls superclass method
# File lib/slosilo/migration/attr_encrypted.rb, line 8
def attr_encrypted *a
  # push a module onto the inheritance hierarchy
  # this allows calling super in classes
  include(accessors = Module.new)
  accessors.module_eval do 
    a.each do |attr|
      define_method "#{attr}=" do |value|
        super(EncryptedAttributes.encrypt value)
      end
      define_method attr do
        EncryptedAttributes.decrypt(super())
      end
    end
  end
end