Class: Trafaret::Chain

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, #|

Constructor Details

This class inherits a constructor from Trafaret::Validator

Instance Method Details

#&(other) ⇒ Object



42
43
44
# File 'lib/trafaret/validators.rb', line 42

def &(other)
  Trafaret::Chain.new(*validators, other)
end

#validate(data) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/trafaret/validators.rb', line 34

def validate(data)
  @validators.each do |v|
    data = v.call(data)
    return data if data.is_a? Trafaret::Error
  end
  data
end