forked from ontoportal/goo
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from ontoportal-lirmm/feature/implement-new-va…
…lidators Feature: Implement new validators
- Loading branch information
1 parent
e1cdf2b
commit b5ddfa3
Showing
12 changed files
with
405 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Goo | ||
module Validators | ||
class DistinctOf < ValidatorBase | ||
include Validator | ||
|
||
key :distinct_of_ | ||
|
||
error_message ->(obj) { "`#{@attr}` must be distinct of `#{@property}`"} | ||
|
||
validity_check -> (obj) do | ||
return true if self.class.empty_value?(@value) | ||
|
||
self.distinct?(@inst, @property, @value) | ||
end | ||
|
||
def initialize(inst, attr, value, key) | ||
super(inst, attr, value) | ||
@property = self.class.property(key) | ||
end | ||
|
||
|
||
|
||
def distinct?(inst, property, value) | ||
target_values = self.class.attr_value(property, inst) | ||
current_values = Array(value) | ||
|
||
!current_values.any?{ |x| self.find_any?(target_values, x)} | ||
end | ||
def find_any?(array, value) | ||
array.any?{ |x| self.class.equivalent_value?(value, x)} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Goo | ||
module Validators | ||
class InverseOf < ValidatorBase | ||
include Validator | ||
|
||
key :inverse_of_ | ||
|
||
error_message ->(obj) { | ||
"`#{@attr}` must be the inverse of ``#{@property}``" | ||
} | ||
|
||
validity_check -> (obj) do | ||
return true if self.class.empty_value?(@value) | ||
|
||
return Array(@value).select{|x| not inverse?(@property,x, @inst)}.empty? | ||
end | ||
|
||
def initialize(inst, attr, value, key) | ||
super(inst, attr, value) | ||
@property = self.class.property(key) | ||
end | ||
|
||
def inverse?(attr, value, source_object) | ||
if self.class.respond_to?(attr, value) | ||
target_values = self.class.attr_value(attr, value) | ||
return target_values.any?{ |target_object| self.class.equivalent_value?(target_object, source_object)} | ||
end | ||
|
||
false | ||
end | ||
|
||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Goo | ||
module Validators | ||
class SuperiorEqualTo < ValidatorBase | ||
include Validator | ||
|
||
key :superior_equal_to_ | ||
|
||
error_message ->(obj) { | ||
"`#{@attr}` must be superior or equal to `#{@property}`" | ||
} | ||
|
||
validity_check -> (obj) do | ||
target_values = self.class.attr_value(@property, @inst) | ||
|
||
return true if target_values.empty? | ||
|
||
return @value >= target_values.first | ||
end | ||
|
||
def initialize(inst, attr, value, key) | ||
super(inst, attr, value) | ||
@property = self.class.property(key) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Goo | ||
module Validators | ||
class Symmetric < ValidatorBase | ||
include Validator | ||
|
||
key :symmetric | ||
|
||
error_message ->(obj) { | ||
"`#{@attr}` must be symmetric" | ||
} | ||
|
||
validity_check -> (obj) do | ||
return true if self.class.empty_value?(@value) | ||
|
||
return Array(@value).select{|x| not symmetric?(@attr,x, @inst)}.empty? | ||
end | ||
|
||
def symmetric?(attr, value, source_object) | ||
if respond_to?(attr, value) | ||
target_values = self.class.attr_value(attr, value) | ||
return target_values.any?{ |target_object| self.class.equivalent_value?(target_object, source_object)} | ||
end | ||
|
||
return false | ||
end | ||
|
||
def respond_to?(attr, object) | ||
object && object.respond_to?(attr) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.