21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/range_validator.rb', line 21
def validate_each(record, attribute, value)
unless value.is_a? Range
record.errors.add(attribute, :not_a_range)
return
end
options.slice(*OPTIONS).each do |option, option_value|
other_records = retrieve_other_records(record, option_value)
if option == :overlapping && other_records.blank?
record.errors.add(attribute, :no_overlap)
end
other_records.each do |other_record|
overlap = value.overlaps? other_record.send(attribute)
if option == :overlapping && !overlap
record.errors.add(attribute, :no_overlap)
elsif option == :not_overlapping && overlap
record.errors.add(attribute, :overlap)
end
end
end
end
|