Sha256: ed9e0e59037d0be161ef1ef70e7641d9baab00a9b58964a878dcda2dabd90ea4
Contents?: true
Size: 849 Bytes
Versions: 9
Compression:
Stored size: 849 Bytes
Contents
#!/usr/bin/env ruby require 'kwalify' require 'yaml' ## load schema definition schema = YAML.load_file('answers-schema.yaml') ## create validator for answers validator = Kwalify::Validator.new(schema) { |value, rule, path, errors| case rule.name when 'Answer' if value['answer'] == 'bad' reason = value['reason'] if !reason || reason.empty? msg = "reason is required when answer is 'bad'." errors << Kwalify::ValidationError.new(msg, path) end end end } ## load YAML document input = ARGF.read() document = YAML.load(input) ## validate errors = validator.validate(document) if errors.empty? puts "Valid." else puts "*** INVALID!" errors.each do |error| # error.class == Kwalify::ValidationError puts " - [#{error.path}] : #{error.message}" end end
Version data entries
9 entries across 7 versions & 4 rubygems