Module: AttrKeyring::ClassMethods

Defined in:
lib/attr_keyring.rb

Instance Method Summary collapse

Instance Method Details

#attr_encrypt(*attributes) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/attr_keyring.rb', line 45

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 = {}) ⇒ Object



41
42
43
# File 'lib/attr_keyring.rb', line 41

def attr_keyring(keyring, options = {})
  self.keyring = Keyring.new(keyring, options)
end

#define_attr_encrypt_reader(attribute) ⇒ Object



61
62
63
64
65
# File 'lib/attr_keyring.rb', line 61

def define_attr_encrypt_reader(attribute)
  define_method(attribute) do
    attr_decrypt_column(attribute)
  end
end

#define_attr_encrypt_writer(attribute) ⇒ Object



55
56
57
58
59
# File 'lib/attr_keyring.rb', line 55

def define_attr_encrypt_writer(attribute)
  define_method("#{attribute}=") do |value|
    attr_encrypt_column(attribute, value)
  end
end

#inherited(subclass) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/attr_keyring.rb', line 33

def inherited(subclass)
  super

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