Module: Slosilo::Migration::EncryptedAttributes::ClassMethods

Defined in:
lib/slosilo/migration/attr_encrypted.rb

Instance Method Summary collapse

Instance Method Details

#attr_encrypted(*a) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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