lib/attr_encrypted.rb in shuber-attr_encrypted-1.0.7 vs lib/attr_encrypted.rb in shuber-attr_encrypted-1.0.8

- old
+ new

@@ -150,12 +150,12 @@ attr_reader encrypted_attribute_name.to_sym unless instance_methods.include?(encrypted_attribute_name) attr_writer encrypted_attribute_name.to_sym unless instance_methods.include?("#{encrypted_attribute_name}=") define_class_method "encrypt_#{attribute}" do |value| if options[:if] && !options[:unless] - if value.nil? - encrypted_value = nil + if value.nil? || (value.is_a?(String) && value.empty?) + encrypted_value = value else value = Marshal.dump(value) if options[:marshal] encrypted_value = options[:encryptor].send options[:encrypt_method], options.merge(:value => value) encrypted_value = [encrypted_value].pack(options[:encode]) if options[:encode] end @@ -165,11 +165,11 @@ end end define_class_method "decrypt_#{attribute}" do |encrypted_value| if options[:if] && !options[:unless] - if encrypted_value.nil? - decrypted_value = nil + if encrypted_value.nil? || (encrypted_value.is_a?(String) && encrypted_value.empty?) + decrypted_value = encrypted_value else encrypted_value = encrypted_value.unpack(options[:encode]).to_s if options[:encode] decrypted_value = options[:encryptor].send(options[:decrypt_method], options.merge(:value => encrypted_value)) decrypted_value = Marshal.load(decrypted_value) if options[:marshal] end \ No newline at end of file