These are chat archives for dry-rb/chat

1st
Jun 2018
Roland Laurès
@ShamoX
Jun 01 2018 10:00
Hi all, I think I found something about that, but I can't find it again. Is it possible to be precise about the error(s) we found in a validation block ?
for example I have data like this :
data = {
  rooms: [{ id: 1, area: 10}, { id: 2, area: 11}],
  interconnections: [
    { room_ids: [1, -1], kind: 'door'},
    { room_ids: [2, -1], kind: 'window'},
    { room_ids: [1, 2], kind: 'door'},
    { room_ids: [3, -1], kind: 'window'}
  ]
}
Roland Laurès
@ShamoX
Jun 01 2018 10:06
Then a validation block like this is not precise but this is what I'm able to do with my knowledge :
validate(interconnections_consistency: %i[rooms interconnections]) do | rooms, interconnections|
  declared_room_ids = rooms.map { |room| room[:id] }
  interconnections.all? do |interconnection|
    interconnection[:room_ids].all? { |room_id| declared_room_ids.include? room_id }
  end
end
But I can't say that the error is interconnections_consistency => { 3 => ['Unknown room id: 3'] } which is what I would like to say.
(I'll also accept -1, because it is designating the exterior).