lib/blind_index/mongoid.rb in blind_index-2.0.2 vs lib/blind_index/mongoid.rb in blind_index-2.1.0
- old
+ new
@@ -24,25 +24,34 @@
bi[:bidx_attribute]
end
criterion[bidx_key] =
if value.is_a?(Array)
- value.map { |v| BlindIndex.generate_bidx(v, bi) }
+ value.map { |v| BlindIndex.generate_bidx(v, **bi) }
else
- BlindIndex.generate_bidx(value, bi)
+ BlindIndex.generate_bidx(value, **bi)
end
end
end
end
super(criterion)
end
end
module UniquenessValidator
+ def validate_each(record, attribute, value)
+ klass = record.class
+ if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
+ value = record.read_attribute_for_validation(bi[:bidx_attribute])
+ end
+ super(record, attribute, value)
+ end
+
+ # change attribute name here instead of validate_each for better error message
def create_criteria(base, document, attribute, value)
- if base.respond_to?(:blind_indexes) && (bi = base.blind_indexes[attribute])
- value = BlindIndex.generate_bidx(value, bi)
+ klass = document.class
+ if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
attribute = bi[:bidx_attribute]
end
super(base, document, attribute, value)
end
end