class SchemaMatcher::Assertion

Attributes

errors[R]
last_error_message[R]
options[R]
payload[R]
schema_name[R]

Public Class Methods

new(schema_name, payload, options = {}) click to toggle source
# File lib/schema_matcher/assertion.rb, line 8
def initialize(schema_name, payload, options = {})
  @schema_name = schema_name.to_sym
  @payload = payload
  @options = options
end

Public Instance Methods

valid?() click to toggle source
# File lib/schema_matcher/assertion.rb, line 14
def valid?
  @errors = JSON::Validator.fully_validate(schema, payload, validator_options)
  return true if @errors.empty?

  false
end

Private Instance Methods

array?() click to toggle source
# File lib/schema_matcher/assertion.rb, line 37
def array?
  options.key?(:array) ? options[:array] : payload.is_a?(Array)
end
schema() click to toggle source
# File lib/schema_matcher/assertion.rb, line 25
def schema
  entity_schema =
    if array?
      { 'type' => 'array', 'items' => SchemaMatcher.schema[schema_name] }
    else
      SchemaMatcher.schema[schema_name]
    end
  entity_schema
    .merge('$schema' => SchemaMatcher::ExtendedSchema::SCHEMA_URI)
    .merge!(definitions: SchemaMatcher.schema)
end
validator_options() click to toggle source
# File lib/schema_matcher/assertion.rb, line 41
def validator_options
  {
    strict: true
  }
end