demarches-normaliennes/app/models/logic/eq.rb

33 lines
868 B
Ruby
Raw Normal View History

2022-06-09 13:48:45 +02:00
class Logic::Eq < Logic::BinaryOperator
def operation = :==
def errors(stable_ids = [])
errors = [@left, @right]
.filter { |term| term.type == :unmanaged }
.map { |term| { type: :unmanaged, stable_id: term.stable_id } }
2022-06-09 13:48:45 +02:00
if !Logic.compatible_type?(@left, @right)
errors << {
type: :incompatible,
stable_id: @left.try(:stable_id),
right: @right,
operator_name: self.class.name
}
elsif @left.type == :enum &&
!left.options.map(&:second).include?(right.value)
errors << {
type: :not_included,
stable_id: @left.stable_id,
right: @right
}
2022-06-09 13:48:45 +02:00
end
errors + @left.errors(stable_ids) + @right.errors(stable_ids)
end
def ==(other)
self.class == other.class &&
[@left, @right].permutation.any? { |p| p == [other.left, other.right] }
end
end