class Tardef::Validator::Syntax

Public Class Methods

new(schema_path) click to toggle source
Calls superclass method Tardef::Validator::Base::new
# File lib/tardef/validator/syntax.rb, line 8
def initialize(schema_path)
  super()
  @schema_path = schema_path
end

Public Instance Methods

validate(obj) click to toggle source
# File lib/tardef/validator/syntax.rb, line 13
def validate(obj)
  schema = ::YAML.load(open(@schema_path))
  data = obj.to_hash
  validator = Kwalify::Validator.new(schema)
  errors = validator.validate(data)
  
  if (errors && !errors.empty?)
    for e in errors
      @errors << "Schema error: [#{e.path}] #{e.message}"
    end
  end
  @errors
end