module AttrKeyring::ClassMethods

Public Instance Methods

attr_encrypt(*attributes) click to toggle source
# File lib/attr_keyring.rb, line 47
def attr_encrypt(*attributes)
  self.encrypted_attributes ||= []
  encrypted_attributes.push(*attributes)

  attributes.each do |attribute|
    define_attr_encrypt_writer(attribute)
    define_attr_encrypt_reader(attribute)
  end
end
attr_keyring(keyring, options = {}) click to toggle source
# File lib/attr_keyring.rb, line 43
def attr_keyring(keyring, options = {})
  self.keyring = Keyring.new(keyring, options)
end
define_attr_encrypt_reader(attribute) click to toggle source
# File lib/attr_keyring.rb, line 63
def define_attr_encrypt_reader(attribute)
  define_method(attribute) do
    attr_decrypt_column(attribute)
  end
end
define_attr_encrypt_writer(attribute) click to toggle source
# File lib/attr_keyring.rb, line 57
def define_attr_encrypt_writer(attribute)
  define_method("#{attribute}=") do |value|
    attr_encrypt_column(attribute, value)
  end
end
inherited(subclass) click to toggle source
Calls superclass method
# File lib/attr_keyring.rb, line 35
def inherited(subclass)
  super

  subclass.encrypted_attributes = encrypted_attributes.dup
  subclass.keyring = keyring
  subclass.keyring_column_name = keyring_column_name
end