class

Tryst::UI::WidgetValidators

Inherits Reference < Object

@api private

Registry of per-node-type validators, mirroring Tryst::CommandInterceptors's own register(type, ...)/for_type(type) shape. Validator (the coordinator) walks the whole Document exactly once; at each node it looks up WidgetValidators.for_type(node.type) and calls every validator registered there.

Unlike a Tryst::CommandInterceptors entry (which "claims" a call and returns its result), a widget validator has nothing to return and nothing to claim exclusively - multiple validators for the same type can coexist freely, and there's no ambiguity to detect.

Registering a validator for a type is purely additive: a custom or third-party widget can call .register to get its own contract checked without editing this file or Validator, the same way a custom widget can register a CommandInterceptors entry without editing app.cr.

Class methods

describe(node : Node | Nil) : String

Shared node-describing helper every validator's error messages use ("#label(:name)" or "an unnamed #label") - kept here rather than duplicated per validator, since every one of them needs it.

Source
for_type(type : Symbol | String) : Array(ValidatorProc)

Every validator registered for type, in registration order - empty if none are.

Source
register(type : Symbol | String, &block : Node, Node | Nil, Document, Array(String) -> Nil) : Nil
Source