Class: Ask::Schema::Validator
- Inherits:
-
Object
- Object
- Ask::Schema::Validator
- 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
-
#initialize(schema_class) ⇒ Validator
constructor
A new instance of Validator.
-
#valid? ⇒ Boolean
Check if the schema is valid without raising.
-
#validate! ⇒ nil
Run all validations, raising on the first error.
Constructor Details
#initialize(schema_class) ⇒ Validator
Returns a new instance of Validator.
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.
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.
25 26 27 |
# File 'lib/ask/schema/validator.rb', line 25 def validate! validate_circular_references! end |