Class: JSONSkooma::Keywords::Unevaluated::UnevaluatedItems
- Defined in:
- lib/json_skooma/keywords/unevaluated/unevaluated_items.rb
Constant Summary collapse
- LOOKUP_KEYWORDS =
%w[items unevaluatedItems prefixItems contains].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 49 50 51 52 |
# File 'lib/json_skooma/keywords/unevaluated/unevaluated_items.rb', line 18 def evaluate(instance, result) contains_indices = Set.new last_evaluated_item = -1 result.parent.collect_annotations(instance, keys: LOOKUP_KEYWORDS) do |node| next contains_indices += node.annotation if node.key == "contains" i = node.annotation next result.discard if i == true last_evaluated_item = i if node.key == "prefixItems" && i > last_evaluated_item end annotation = nil error = [] instance.each_with_index do |item, index| next if last_evaluated_item >= index next if contains_indices.include?(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 |