class IfMissingAttribute

Add a new ‘ifmissing’ attribute which emits either an error or warning depending on its value.

Public Class Methods

validate(current_schema, data, fragments, validator, options = {}) click to toggle source
Calls superclass method
# File lib/aspace_client/archivesspace_json_schema.rb, line 7
def self.validate(current_schema, data, fragments, validator, options = {})
  super

  if data.is_a?(Hash)
    current_schema.schema['properties'].each do |property, property_schema|
      if (property_schema['ifmissing'] && !data.has_key?(property))
        message = nil

        if property_schema['ifmissing'] == 'error'
          message = "ERROR: The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}'"
        elsif property_schema['ifmissing'] == 'warn'
          message = "WARNING: The property '#{build_fragment(fragments)}' did not contain a required property of '#{property}'"
        end

        if message
          validation_error(message, fragments, current_schema, self, options[:record_errors])
        end
      end
    end
  end
end