Module: Coradoc::Validation
- Defined in:
- lib/coradoc/validation.rb
Overview
Document validation framework for schema-based validation.
This module provides a flexible validation framework for ensuring documents conform to expected structures and rules.
Defined Under Namespace
Modules: Rules Classes: Error, Result, Rule, Schema, SchemaGenerator
Class Attribute Summary collapse
-
.default_schema ⇒ Schema
Get the default validation schema.
Class Method Summary collapse
-
.auto_schema(model_class) ⇒ Schema
Generate a validation schema from a CoreModel class.
-
.define { ... } ⇒ Schema
Define a validation schema.
-
.guard_unresolved_includes!(model, format_module) ⇒ Object
Serialization boundary check: formats that cannot represent an unresolved include edge (FormatModule::Interface #preserves_unresolved_includes? == false) must not silently drop the content — raise UnresolvedIncludesError instead, pointing at the hydration step (resolve_includes).
-
.unresolved_include_targets(model) ⇒ Object
Targets of every unresolved
include::edge in the tree (deduplicated, in document order). -
.validate(document) ⇒ Result
Validate a document with default schema.
- .walk_nodes(node) {|node| ... } ⇒ Object
Class Attribute Details
Class Method Details
.auto_schema(model_class) ⇒ Schema
Generate a validation schema from a CoreModel class
657 658 659 |
# File 'lib/coradoc/validation.rb', line 657 def auto_schema(model_class, **) SchemaGenerator.generate(model_class, **) end |
.define { ... } ⇒ Schema
Define a validation schema
643 644 645 |
# File 'lib/coradoc/validation.rb', line 643 def define(&) Schema.define(&) end |
.guard_unresolved_includes!(model, format_module) ⇒ Object
Serialization boundary check: formats that cannot represent an unresolved include edge (FormatModule::Interface #preserves_unresolved_includes? == false) must not silently drop the content — raise UnresolvedIncludesError instead, pointing at the hydration step (resolve_includes).
50 51 52 53 54 55 56 57 |
# File 'lib/coradoc/validation.rb', line 50 def guard_unresolved_includes!(model, format_module) return if format_module.preserves_unresolved_includes? targets = unresolved_include_targets(model) return if targets.empty? raise Coradoc::UnresolvedIncludesError, targets end |
.unresolved_include_targets(model) ⇒ Object
Targets of every unresolved include:: edge in the tree
(deduplicated, in document order). A document is "unresolved"
when it was parsed in graph mode and never went through
Coradoc.resolve_includes.
37 38 39 40 41 42 43 |
# File 'lib/coradoc/validation.rb', line 37 def unresolved_include_targets(model) targets = [] walk_nodes(model) do |node| targets << node.target if node.is_a?(Coradoc::CoreModel::Include) end targets.uniq end |
.validate(document) ⇒ Result
Validate a document with default schema
665 666 667 |
# File 'lib/coradoc/validation.rb', line 665 def validate(document) default_schema.validate(document) end |
.walk_nodes(node) {|node| ... } ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/coradoc/validation.rb', line 59 def walk_nodes(node, &block) return unless node.is_a?(Coradoc::CoreModel::Base) yield node return unless node.is_a?(Coradoc::CoreModel::HasChildren) children = node.children return unless children children.each { |child| walk_nodes(child, &block) } end |