Class: JSONSkooma::Keywords::Draft201909::UnevaluatedItems
- Defined in:
- lib/json_skooma/keywords/draft_2019_09/unevaluated_items.rb
Constant Summary collapse
- LOOKUP_KEYWORDS =
%w[items additionalItems unevaluatedItems].freeze
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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/json_skooma/keywords/draft_2019_09/unevaluated_items.rb', line 18 def evaluate(instance, result) last_evaluated_item = -1 result.parent.collect_annotations(instance, keys: LOOKUP_KEYWORDS) do |node| i = node.annotation next result.discard if i == true last_evaluated_item = i if node.key == "items" && i > last_evaluated_item end annotation = nil error = [] instance.each_with_index do |item, index| next if last_evaluated_item >= index if json.evaluate(item, result).passed? annotation = true else error << index # reset to passed for the next iteration result.success end end if error.any? result.failure(error) else result.annotate(annotation) end end |