Class: Ask::Schema::Validator

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

Overview

Validates schema definitions for structural issues such as circular references in named definitions (‘$defs`).

Uses DFS-based topological sort with three-color marking (WHITE/GRAY/BLACK) to detect cycles in definition dependency graphs.

Constant Summary collapse

WHITE =

Node states for DFS-based topological sort

:white
GRAY =

No mark (unvisited)

:gray
BLACK =

Temporary mark (currently being processed)

:black

Instance Method Summary collapse

Constructor Details

#initialize(schema_class) ⇒ Validator

Returns a new instance of Validator.

Parameters:

  • schema_class (Class<Schema>)

    The schema class to validate



17
18
19
# File 'lib/ask/schema/validator.rb', line 17

def initialize(schema_class)
  @schema_class = schema_class
end

Instance Method Details

#valid?Boolean

Check if the schema is valid without raising.

Returns:

  • (Boolean)


32
33
34
35
36
37
# File 'lib/ask/schema/validator.rb', line 32

def valid?
  validate!
  true
rescue ValidationError
  false
end

#validate!nil

Run all validations, raising on the first error.

Returns:

  • (nil)

    if the schema is valid

Raises:



25
26
27
# File 'lib/ask/schema/validator.rb', line 25

def validate!
  validate_circular_references!
end