From cd67a526d2f14c2c2d74ee5bce8e473321c17cb1 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Tue, 28 Feb 2023 02:51:10 +0100 Subject: [PATCH] migrate uniqueness validator to the new DSL --- lib/goo/validators/implementations/unique.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/goo/validators/implementations/unique.rb diff --git a/lib/goo/validators/implementations/unique.rb b/lib/goo/validators/implementations/unique.rb new file mode 100644 index 000000000..feb13a4b5 --- /dev/null +++ b/lib/goo/validators/implementations/unique.rb @@ -0,0 +1,20 @@ +module Goo + module Validators + class Unique < ValidatorBase + include Validator + + key :unique + + error_message ->(obj) { "`#{@attr}` must be unique. " + + "There are other model instances with the same attribute value `#{@value}`."} + + validity_check -> (obj) do + return true if @value.nil? + + !Goo::SPARQL::Queries.duplicate_attribute_value?(@inst,@attr) + end + + + end + end +end \ No newline at end of file