Class: Trafaret::Case
Instance Attribute Summary
Attributes inherited from Validator
#converters, #options
Instance Method Summary
collapse
Methods inherited from Validator
#&, #===, #add, #convert, #failure, #initialize, #perform_convert, #to, #validate, #|
Instance Method Details
#call(data) ⇒ Object
171
172
173
174
175
176
177
178
179
|
# File 'lib/trafaret/validators.rb', line 171
def call(data)
@whens.each do |trafaret, blk|
val = trafaret.call(data)
unless val.is_a?(Trafaret::Error)
return blk.call(val)
end
end
failure('Case does not match')
end
|
#prepare ⇒ Object
162
163
164
165
|
# File 'lib/trafaret/validators.rb', line 162
def prepare
@whens = []
@converters.shift.call(self)
end
|
#when(trafaret, &blk) ⇒ Object