demarches-normaliennes/app/models/logic/include_operator.rb
2022-09-26 10:21:15 +02:00

29 lines
587 B
Ruby

class Logic::IncludeOperator < Logic::BinaryOperator
def operation = :include?
def errors(stable_ids = [])
result = []
if left_not_a_list?
result << { type: :required_list }
elsif right_value_not_in_list?
result << {
type: :not_included,
stable_id: @left.stable_id,
right: @right
}
end
result + @left.errors(stable_ids) + @right.errors(stable_ids)
end
private
def left_not_a_list?
@left.type != :enums
end
def right_value_not_in_list?
!@left.options.map(&:second).include?(@right.value)
end
end