Class: Trafaret::Or
- Inherits:
-
ADT
show all
- Defined in:
- lib/trafaret/validators.rb
Instance Attribute Summary
Attributes inherited from ADT
#validators
Attributes inherited from Validator
#converters, #options
Instance Method Summary
collapse
Methods inherited from ADT
#prepare
Methods inherited from Validator
#&, #===, #add, #call, #convert, #failure, #initialize, #perform_convert, #prepare, #to
Instance Method Details
#validate(data) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/trafaret/validators.rb', line 15
def validate(data)
errors = []
@validators.each do |v|
res = v.call(data)
if res.is_a? Trafaret::Error
errors << res
else
return res
end
end
return failure errors
end
|
#|(other) ⇒ Object
28
29
30
|
# File 'lib/trafaret/validators.rb', line 28
def |(other)
Trafaret::Or.new(*validators, other)
end
|