Module: ActsAsEncrypted::Acts::Encrypted::InstanceMethods::ClassMethods

Defined in:
lib/acts_as_encrypted.rb

Instance Method Summary collapse

Instance Method Details

#encrypt_fields(*args) ⇒ Object Also known as: encrypt_field

Class methods

Our encrypt_field function - when called sets up the callback hooks and the lazy decryption



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/acts_as_encrypted.rb', line 68

def encrypt_fields(*args)
  args.each do |fn|
    before_save(EncryptionWrapper.new(fn))
    after_save(EncryptionWrapper.new(fn))
    fn = fn.to_s
    # if the initializer says 'nil', then it's encrypted - since that's the default value
    class_eval "    # This is a custom accessor that\n    def \#{fn}\n      if field_is_encrypted?(\\\"\#{fn}\\\")\n        decrypt_field(\\\"\#{fn}\\\")\n      else\n        \#{fn}_safe\n      end\n    end\n    HERE\n    \n    class_eval <<-THERE\n    def \#{fn}_safe\n      read_attribute \\\"\#{fn}\\\" \n    end\n    THERE\n  end\nend\n"