Class: GenerativeUI::ComponentValidator
- Inherits:
-
Object
- Object
- GenerativeUI::ComponentValidator
- Defined in:
- lib/generative_ui/component_validator.rb
Defined Under Namespace
Classes: Result
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(component, catalog) ⇒ ComponentValidator
constructor
A new instance of ComponentValidator.
Constructor Details
#initialize(component, catalog) ⇒ ComponentValidator
Returns a new instance of ComponentValidator.
15 16 17 18 |
# File 'lib/generative_ui/component_validator.rb', line 15 def initialize(component, catalog) @component = component @catalog = catalog end |
Class Method Details
.call(component, catalog:) ⇒ Object
11 12 13 |
# File 'lib/generative_ui/component_validator.rb', line 11 def self.call(component, catalog:) new(component, catalog).call end |
Instance Method Details
#call ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/generative_ui/component_validator.rb', line 20 def call unless component.name.is_a?(String) && component.name.present? return invalid(['component must be a non-empty string']) end return invalid(["unknown component: #{component.name}"]) unless catalog.fetch(component.name) errors = JSONSchemer.schema(schema).validate(component.to_h).flat_map { |error| format_error(error) } Result.new(valid: errors.empty?, errors:) end |