Class: Kwalify::Validator
- Inherits:
-
Object
- Object
- Kwalify::Validator
- 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
Instance Attribute Summary collapse
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
- #_inspect ⇒ Object
-
#initialize(hash, &block) ⇒ Validator
constructor
A new instance of Validator.
- #validate(value) ⇒ Object
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
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
33 34 35 |
# File 'lib/kwalify/validator.rb', line 33 def rule @rule end |
Instance Method Details
#_inspect ⇒ Object
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 |