Class: JDDF::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/jddf/validator.rb

Overview

Validator

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#max_depthObject

Returns the value of attribute max_depth.



251
252
253
# File 'lib/jddf/validator.rb', line 251

def max_depth
  @max_depth
end

#max_errorsObject

Returns the value of attribute max_errors.



252
253
254
# File 'lib/jddf/validator.rb', line 252

def max_errors
  @max_errors
end

Instance Method Details

#validate(schema, instance) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/jddf/validator.rb', line 254

def validate(schema, instance)
  vm = VM.new
  vm.max_depth = max_depth
  vm.max_errors = max_errors
  vm.root_schema = schema
  vm.instance_tokens = []
  vm.schema_tokens = [[]]
  vm.errors = []

  begin
    vm.validate(schema, instance)
  rescue MaxErrorsError # rubocop:disable Lint/HandleExceptions
    # There is nothing to do here. MaxErrorsError is just a circuit-breaker.
  end

  vm.errors
end