2022-09-09 15:36:50 +02:00
|
|
|
class Logic::IncludeOperator < Logic::BinaryOperator
|
|
|
|
def operation = :include?
|
|
|
|
|
2022-09-26 21:11:43 +02:00
|
|
|
def errors(type_de_champs = [])
|
2022-09-09 15:36:50 +02:00
|
|
|
result = []
|
|
|
|
|
2022-09-26 21:07:43 +02:00
|
|
|
if left_not_a_list?(type_de_champs)
|
2022-09-09 15:36:50 +02:00
|
|
|
result << { type: :required_list }
|
2022-09-26 21:19:00 +02:00
|
|
|
elsif right_value_not_in_list?(type_de_champs)
|
2022-09-09 15:36:50 +02:00
|
|
|
result << {
|
|
|
|
type: :not_included,
|
|
|
|
stable_id: @left.stable_id,
|
|
|
|
right: @right
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-09-26 21:11:43 +02:00
|
|
|
result + @left.errors(type_de_champs) + @right.errors(type_de_champs)
|
2022-09-09 15:36:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-09-26 21:07:43 +02:00
|
|
|
def left_not_a_list?(type_de_champs)
|
|
|
|
@left.type(type_de_champs) != :enums
|
2022-09-09 15:36:50 +02:00
|
|
|
end
|
|
|
|
|
2022-09-26 21:19:00 +02:00
|
|
|
def right_value_not_in_list?(type_de_champs)
|
|
|
|
!@left.options(type_de_champs).map(&:second).include?(@right.value)
|
2022-09-09 15:36:50 +02:00
|
|
|
end
|
|
|
|
end
|