Class: Unitsdb::Database::ReferenceValidator
- Inherits:
-
Object
- Object
- Unitsdb::Database::ReferenceValidator
- Defined in:
- lib/unitsdb/database/reference_validator.rb
Overview
Validates that every cross-entity reference in a Database points
at an entity that actually exists. Single source of truth for
both Database#validate_references and the
unitsdb validate references CLI command.
Composition:
ReferenceValidator — public façade; returns a Result
IdRegistry — builds {type => {key => path}} from db
ReferenceChecker — walks each reference kind
LookupStrategies — pluggable "is this ref valid?" predicates
Defined Under Namespace
Classes: Result
Class Method Summary collapse
-
.validate(database) ⇒ Object
Convenience entry-point used by Database#validate_references.
Instance Method Summary collapse
-
#initialize(database) ⇒ ReferenceValidator
constructor
A new instance of ReferenceValidator.
- #validate ⇒ Object
Constructor Details
#initialize(database) ⇒ ReferenceValidator
Returns a new instance of ReferenceValidator.
24 25 26 |
# File 'lib/unitsdb/database/reference_validator.rb', line 24 def initialize(database) @database = database end |
Class Method Details
.validate(database) ⇒ Object
Convenience entry-point used by Database#validate_references.
35 36 37 |
# File 'lib/unitsdb/database/reference_validator.rb', line 35 def self.validate(database) new(database).validate.invalid end |
Instance Method Details
#validate ⇒ Object
28 29 30 31 32 |
# File 'lib/unitsdb/database/reference_validator.rb', line 28 def validate registry = IdRegistry.build(@database) checker = ReferenceChecker.new(registry, LookupStrategies::ALL) Result.new(invalid: checker.check_all(@database)) end |