Class: JSONSkooma::Keywords::Applicator::Properties

Inherits:
Base
  • Object
show all
Defined in:
lib/json_skooma/keywords/applicator/properties.rb

Instance Attribute Summary

Attributes inherited from Base

#json, #parent_schema

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
# File 'lib/json_skooma/keywords/applicator/properties.rb', line 11

def evaluate(instance, result)
  annotation = []
  err_names = []
  instance.each do |name, item|
    next unless json.value.key?(name)

    result.call(item, name) do |subresult|
      json[name].evaluate(item, subresult)
      if subresult.passed?
        annotation << name
      else
        err_names << name
      end
    end
  end

  return result.annotate(annotation) if err_names.empty?

  result.failure("Properties #{err_names.join(", ")} are invalid")
end