2021-03-11 10:22:49 +01:00
|
|
|
class GeoJSONValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
2023-04-21 17:26:28 +02:00
|
|
|
if options[:allow_nil] == false && value.nil?
|
|
|
|
record.errors.add(attribute, :blank, message: options[:message] || "ne peut pas être vide")
|
|
|
|
end
|
|
|
|
|
2023-04-07 15:24:28 +02:00
|
|
|
unless value.blank? || GeojsonService.valid?(value)
|
2023-04-21 17:26:28 +02:00
|
|
|
record.errors.add(attribute, :invalid_geometry, message: options[:message] || "n'est pas un GeoJSON valide")
|
2021-03-11 10:22:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|