lib/mongoid/kms.rb in mongoid-kms-0.0.8 vs lib/mongoid/kms.rb in mongoid-kms-0.0.9

- old
+ new

@@ -27,10 +27,18 @@ def self.key configuration[:key] end + def self.bson_class + if defined? Moped::BSON + Moped::BSON + elsif defined? BSON + BSON + end + end + module ClassMethods def encrypt_field(field_name, value) Mongoid::Kms.kms.encrypt({ key_id: Mongoid::Kms.key, plaintext: value, @@ -59,10 +67,10 @@ encrypted_field_name = "kms_secure_#{field_name}" @ksm_field_map ||= {} @ksm_field_map[field_name.to_s] = {context: args.delete(:context), type: args.delete(:type)} - field encrypted_field_name, args.merge(type: BSON::Binary) + field encrypted_field_name, args.merge(type: Mongoid::Kms.bson_class::Binary) define_method(field_name) do instance_variable_get("@#{field_name}") || begin v = self.class.decrypt_field(field_name, send("kms_secure_#{field_name}")) instance_variable_set("@#{field_name}", v)