Class: Teek::UI::WidgetValidators Private

Inherits:
Object
  • Object
show all
Defined in:
lib/teek/ui/widget_validators.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Registry of per-node-type validators, mirroring CommandInterceptors' 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.

A registered validator receives (node, parent, document, errors) and must APPEND problem strings to errors - it must never raise itself. Unlike a 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 WidgetValidators.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 teek.rb.

Class Method Summary collapse

Class Method Details

.describe(node) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

Returns:

  • (String)


49
50
51
52
# File 'lib/teek/ui/widget_validators.rb', line 49

def describe(node)
  return 'the document root' unless node
  node.name ? "##{node.type}(:#{node.name})" : "an unnamed ##{node.type}"
end

.for_type(type) ⇒ Array<Proc>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • type (Symbol, String)

Returns:

  • (Array<Proc>)

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



40
41
42
# File 'lib/teek/ui/widget_validators.rb', line 40

def for_type(type)
  validators[type.to_s]
end

.register(type) {|node, parent, document, errors| ... } ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • type (Symbol, String)

    the node type this validator applies to

Yield Parameters:



33
34
35
# File 'lib/teek/ui/widget_validators.rb', line 33

def register(type, &block)
  validators[type.to_s] << block
end