lib/data_taster/flavors.rb in data_taster-0.2.2 vs lib/data_taster/flavors.rb in data_taster-0.3.0
- old
+ new
@@ -28,10 +28,24 @@
end
def encrypt(klass, column, value = nil)
value_to_encrypt = value || default_value_for(column)
- klass.new.encrypt(column, value_to_encrypt)
+ klass_instance = klass.new
+ if klass_instance.respond_to?(:attr_encrypted_encrypt)
+ klass_instance.attr_encrypted_encrypt(column, value_to_encrypt)
+ elsif klass_instance.respond_to?(:encrypt)
+ klass_instance.encrypt(column, value_to_encrypt)
+ else
+ raise encryption_error_message
+ end
+ end
+
+ def encryption_error_message
+ [
+ "DataTaster only supports encryption if your model is configured with attr_encrypted.",
+ "Please visit https://github.com/attr-encrypted/attr_encrypted for more details on setup.",
+ ].join(" ")
end
def default_value_for(column)
case column
when /date_of_birth/, /dob/