10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/validators/proposal/arguments_validator.rb', line 10
def validate record
if record.expects.is_a? Proc
unless record.expects.call(record.arguments)
record.errors.add :arguments, "is invalid"
end
elsif record.arguments.is_a? Hash
case record.expects
when Symbol
validate_expected record, record.expects
when Array
record.expects.each { |sym| validate_expected record, sym }
end
else
record.errors.add :arguments, "must be a hash"
case record.expects
when Symbol
record.errors.add :arguments, "is missing #{record.expects}"
when Array
record.expects.each do |sym|
record.errors.add :arguments, "is missing #{sym}"
end
end
end
end
|