# File lib/couch_potato/extensions/encrypted_property.rb, line 6 def initialize(owner_clazz, name, options = {}) super @options = options end
# File lib/couch_potato/extensions/encrypted_property.rb, line 11 def build(object, json) value = json[name.to_s].nil? ? json[name.to_sym] : json[name.to_s] object.send "#{name}=", decrypt(value) object.instance_variable_set("@encrypted_#{name}", value) end
# File lib/couch_potato/extensions/encrypted_property.rb, line 39 def decrypt(value) if not value.nil? EzCrypto::Key.decrypt_with_password(@options[:password], @options[:salt], Base64.decode64(value)) end end
# File lib/couch_potato/extensions/encrypted_property.rb, line 17 def dirty?(object) object.send("#{name}_changed?") end
# File lib/couch_potato/extensions/encrypted_property.rb, line 33 def encrypt(value) if not value.nil? value.empty? ? value : Base64.encode64(EzCrypto::Key.encrypt_with_password(@options[:password], @options[:salt], value)) end end
# File lib/couch_potato/extensions/encrypted_property.rb, line 45 def encrypted_value(object) object.instance_variable_get("@encrypted_#{name}") end
# File lib/couch_potato/extensions/encrypted_property.rb, line 21 def serialize(json, object) if dirty?(object) or encrypted_value(object).nil? json[name] = encrypt(object.send(name)) else json[name] = encrypted_value(object) end end
# File lib/couch_potato/extensions/encrypted_property.rb, line 29 def value(result, object) result[name] = object.send(name) end