Module: EncryptedAttributes::AR32

Defined in:
lib/encrypted_attributes/ar_32.rb

Instance Method Summary collapse

Instance Method Details

#define_attribute_methods(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/encrypted_attributes/ar_32.rb', line 12

def define_attribute_methods(*args)
  self.encrypted_attributes.each do |column|
    define_method(column) do
      coder = self.class.serialized_attributes[column]
      value = EncryptedAttributes.decrypt(read_attribute(column))

      value = coder ? coder.load(value) : value
      value.freeze
    end

    define_method("#{ column }=".to_sym) do |value|
      coder = self.class.serialized_attributes[column]

      value          = coder ? coder.dump(value) : value
      encrypted_data = EncryptedAttributes.encrypt(value)

      write_attribute(column, encrypted_data)
    end
  end

  super
end

#encrypt(column_name) ⇒ Object



7
8
9
10
# File 'lib/encrypted_attributes/ar_32.rb', line 7

def encrypt(column_name)
  @encrypted_attributes = [] unless defined? @encrypted_columns
  @encrypted_attributes << column_name.to_s
end

#encrypted_attributesObject



3
4
5
# File 'lib/encrypted_attributes/ar_32.rb', line 3

def encrypted_attributes
  @encrypted_attributes
end