2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-06-09 13:48:45 +02:00
|
|
|
class Logic::Eq < Logic::BinaryOperator
|
|
|
|
def operation = :==
|
|
|
|
|
2022-09-26 21:11:43 +02:00
|
|
|
def errors(type_de_champs = [])
|
2022-09-14 10:43:18 +02:00
|
|
|
errors = [@left, @right]
|
2022-09-26 21:07:43 +02:00
|
|
|
.filter { |term| term.type(type_de_champs) == :unmanaged }
|
2022-09-14 10:43:18 +02:00
|
|
|
.map { |term| { type: :unmanaged, stable_id: term.stable_id } }
|
2022-06-09 13:48:45 +02:00
|
|
|
|
2022-09-26 21:20:32 +02:00
|
|
|
if !Logic.compatible_type?(@left, @right, type_de_champs)
|
2022-09-14 10:43:18 +02:00
|
|
|
errors << {
|
|
|
|
type: :incompatible,
|
|
|
|
stable_id: @left.try(:stable_id),
|
|
|
|
right: @right,
|
|
|
|
operator_name: self.class.name
|
|
|
|
}
|
2022-09-26 21:07:43 +02:00
|
|
|
elsif @left.type(type_de_champs) == :enum &&
|
2022-09-26 21:19:00 +02:00
|
|
|
!left.options(type_de_champs).map(&:second).include?(right.value)
|
2022-09-14 10:43:18 +02:00
|
|
|
errors << {
|
|
|
|
type: :not_included,
|
|
|
|
stable_id: @left.stable_id,
|
|
|
|
right: @right
|
|
|
|
}
|
2023-04-25 19:53:06 +02:00
|
|
|
elsif @left.type(type_de_champs) == :enums
|
|
|
|
errors << {
|
|
|
|
type: :required_include,
|
|
|
|
stable_id: @left.try(:stable_id),
|
|
|
|
operator_name: self.class.name
|
|
|
|
}
|
2022-06-09 13:48:45 +02:00
|
|
|
end
|
|
|
|
|
2022-09-26 21:11:43 +02:00
|
|
|
errors + @left.errors(type_de_champs) + @right.errors(type_de_champs)
|
2022-06-09 13:48:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
self.class == other.class &&
|
|
|
|
[@left, @right].permutation.any? { |p| p == [other.left, other.right] }
|
|
|
|
end
|
|
|
|
end
|