Class: Kwalify::Validator

Inherits:
Object
  • Object
show all
Includes:
ErrorHelper
Defined in:
lib/kwalify/validator.rb

Overview

ex.

schema = YAML.load_file('schema.yaml')
validator = Kwalify::Validator.new(schema)
document = YAML.load_file('document.yaml')
error_list = validator.validate(document)
unless error_list.empty?
  error_list.each do |error|
    puts "- [#{error.path}] #{error.message}"
  end
end

Direct Known Subclasses

MetaValidator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ErrorHelper

#_build_message, #assert_error, #schema_error, #validate_error

Constructor Details

#initialize(hash, &block) ⇒ Validator

Returns a new instance of Validator.



29
30
31
32
# File 'lib/kwalify/validator.rb', line 29

def initialize(hash, &block)
   @rule  = Rule.new(hash)
   @block = block
end

Instance Attribute Details

#ruleObject (readonly)

Returns the value of attribute rule.



33
34
35
# File 'lib/kwalify/validator.rb', line 33

def rule
  @rule
end

Instance Method Details

#_inspectObject



36
37
38
# File 'lib/kwalify/validator.rb', line 36

def _inspect
   @rule._inspect
end

#validate(value) ⇒ Object



41
42
43
44
45
# File 'lib/kwalify/validator.rb', line 41

def validate(value)
   path = "";  errors = [];  done = {}
   _validate(value, @rule, path, errors, done)
   return errors
end