Class: GenerativeUI::ComponentTreeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/generative_ui/component_tree_validator.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

TREE_KEY =
'_tree'
MAX_COMPONENTS =
500
MAX_DEPTH =
64
MAX_REFS =
2_000

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component_set, catalog) ⇒ ComponentTreeValidator

Returns a new instance of ComponentTreeValidator.



18
19
20
21
22
23
# File 'lib/generative_ui/component_tree_validator.rb', line 18

def initialize(component_set, catalog)
  @component_set = component_set
  @catalog = catalog
  @errors = {}
  @edges = Hash.new { |hash, key| hash[key] = [] }
end

Class Method Details

.call(component_set, catalog:) ⇒ Object



14
15
16
# File 'lib/generative_ui/component_tree_validator.rb', line 14

def self.call(component_set, catalog:)
  new(component_set, catalog).call
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
# File 'lib/generative_ui/component_tree_validator.rb', line 25

def call
  validate_admission_limits
  return Result.new(valid: false, errors:) if errors.any?

  validate_components
  validate_structure
  Result.new(valid: errors.empty?, errors:)
end