Class: JSONSkooma::Keywords::Draft201909::Items
- Defined in:
- lib/json_skooma/keywords/draft_2019_09/items.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#each_schema, inherited, #initialize, #instance_types, #key, #resolve, set_defaults, #static, value_schema=
Constructor Details
This class inherits a constructor from JSONSkooma::Keywords::Base
Instance Method Details
#evaluate(instance, result) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/json_skooma/keywords/draft_2019_09/items.rb', line 11 def evaluate(instance, result) return if instance.empty? if json.type == "boolean" json.evaluate(instance, result) elsif json.is_a?(JSONSchema) instance.each do |item| json.evaluate(item, result) end result.annotate(true) if result.passed? elsif json.type == "array" annotation = nil error = [] instance.take(json.value.length).each_with_index do |item, index| annotation = index result.call(item, index.to_s) do |subresult| unless json[index].evaluate(item, subresult).passed? error << index end end end return result.failure(error) unless error.empty? result.annotate(annotation) end end |