Class: Lutaml::Qea::Validation::ValidationEngine
- Inherits:
-
Object
- Object
- Lutaml::Qea::Validation::ValidationEngine
- Defined in:
- lib/lutaml/qea/validation/validation_engine.rb
Overview
Main orchestrator for the validation system Coordinates all validators and consolidates results
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#initialize(document, database: nil, **options) ⇒ ValidationEngine
constructor
Creates a new validation engine.
-
#register_validator(name, validator_class) ⇒ void
Registers a custom validator.
-
#valid?(validators: nil) ⇒ Boolean
Checks if validation passed (no errors).
-
#validate(validators: nil) ⇒ ValidationResult
Runs validation using two-phase architecture.
-
#validate_and_display(validators: nil, formatter: :text) ⇒ ValidationResult
Validates and displays the result.
-
#validate_qea_database(context, validators = nil) ⇒ ValidationResult
Validates QEA database integrity.
-
#validate_uml_tree(context, validators = nil) ⇒ ValidationResult
Validates UML document tree structure.
Constructor Details
#initialize(document, database: nil, **options) ⇒ ValidationEngine
Creates a new validation engine
43 44 45 46 47 48 49 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 43 def initialize(document, database: nil, **) @document = document @database = database @options = @registry = ValidatorRegistry.new setup_default_validators end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
32 33 34 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 32 def database @database end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
32 33 34 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 32 def document @document end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
32 33 34 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 32 def @options end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
32 33 34 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 32 def registry @registry end |
Instance Method Details
#register_validator(name, validator_class) ⇒ void
This method returns an undefined value.
Registers a custom validator
166 167 168 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 166 def register_validator(name, validator_class) @registry.register(name, validator_class) end |
#valid?(validators: nil) ⇒ Boolean
Checks if validation passed (no errors)
174 175 176 177 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 174 def valid?(validators: nil) result = validate(validators: validators) !result.has_errors? end |
#validate(validators: nil) ⇒ ValidationResult
Runs validation using two-phase architecture
Phase 1: QEA Database Integrity Validation
-
Validates EA database schema constraints
-
Checks referential integrity
-
Detects orphaned records
-
Finds circular references
Phase 2: UML Tree Structure Validation
-
Validates transformed UML document tree
-
Checks proper nesting
-
Validates duplicate names
-
Verifies type references
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 68 def validate(validators: nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength result = ValidationResult.new context = build_context context[:result] = result # Phase 1: QEA Database Validation phase1_result = validate_qea_database(context, validators) # Phase 2: UML Tree Validation phase2_result = validate_uml_tree(context, validators) # Merge results phase1_result..each { |msg| result. << msg } phase2_result..each { |msg| result. << msg } filter_result(result) end |
#validate_and_display(validators: nil, formatter: :text) ⇒ ValidationResult
Validates and displays the result
155 156 157 158 159 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 155 def validate_and_display(validators: nil, formatter: :text) result = validate(validators: validators) display_result(result, formatter) result end |
#validate_qea_database(context, validators = nil) ⇒ ValidationResult
Validates QEA database integrity
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 91 def validate_qea_database(context, validators = nil) # rubocop:disable Metrics/MethodLength result = ValidationResult.new db_context = context.merge(result: result) database_validators = %i[ referential_integrity orphan circular_reference package ] validator_names = if validators (database_validators & validators) else database_validators end validator_names.each do |name| next unless @registry.registered?(name) @registry.validate(name, db_context) end result end |
#validate_uml_tree(context, validators = nil) ⇒ ValidationResult
Validates UML document tree structure
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/lutaml/qea/validation/validation_engine.rb', line 122 def validate_uml_tree(context, validators = nil) # rubocop:disable Metrics/MethodLength result = ValidationResult.new uml_context = context.merge(result: result) uml_validators = %i[ document_structure class attribute operation association diagram ] validator_names = if validators (uml_validators & validators) else uml_validators end validator_names.each do |name| next unless @registry.registered?(name) @registry.validate(name, uml_context) end result end |