Class: Teek::UI::WidgetTypes Private

Inherits:
Object
  • Object
show all
Defined in:
lib/teek/ui/widget_types.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.

Central registry of WidgetType descriptors, mirroring CommandInterceptors's own register/for_type shape - one registered descriptor per node type is the single source of truth WidgetDSL, Realizer, and Validator each dispatch to for that type's own build/realize/validate behavior.

Unlike CommandInterceptors (consulted per-call with a type already in hand) or WidgetValidators (many validators can share one type), exactly one descriptor owns a given type here, and consumers need the full set up front to drive codegen - so this adds two things CommandInterceptors doesn't need: WidgetTypes.each (enumerate every registered type) and WidgetTypes.on_register (subscribe to every past AND future registration, so load order between this file and a consumer like WidgetDSL never matters).

A descriptor's validator: (see WidgetType) is forwarded into WidgetValidators right here, at registration time, so it's dispatched through the exact same WidgetValidators.for_type call every other validator goes through - Validator itself carries no awareness of descriptors at all.

Class Method Summary collapse

Class Method Details

.each {|widget_type| ... } ⇒ Enumerator

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 if no block given.

Yield Parameters:

Returns:

  • (Enumerator)

    if no block given



58
59
60
61
62
# File 'lib/teek/ui/widget_types.rb', line 58

def each(&block)
  return enum_for(:each) unless block

  types.each_value(&block)
end

.for_type(type) ⇒ WidgetType?

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.

Parameters:

  • type (Symbol, String)

Returns:



52
53
54
# File 'lib/teek/ui/widget_types.rb', line 52

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

.on_register {|widget_type| ... } ⇒ 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.

Subscribes block to every type registered from now on, and immediately replays every type already registered - so a subscriber (namely Teek::UI::WidgetDSL's own codegen) sees every type regardless of whether it loaded before or after this file populated its own built-ins.

Yield Parameters:



71
72
73
74
# File 'lib/teek/ui/widget_types.rb', line 71

def on_register(&block)
  types.each_value(&block)
  callbacks << block
end

.register(widget_type) ⇒ WidgetType

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 widget_type, for chaining.

Parameters:

Returns:

Raises:

  • (ArgumentError)

    if widget_type.type is already registered



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/teek/ui/widget_types.rb', line 35

def register(widget_type)
  key = widget_type.type.to_s
  if types.key?(key)
    raise ArgumentError, "widget type :#{widget_type.type} is already registered"
  end

  types[key] = widget_type
  if widget_type.validator
    WidgetValidators.register(widget_type.type) { |*args| widget_type.validator.call(*args) }
  end
  callbacks.each { |callback| callback.call(widget_type) }

  widget_type
end