Class: Trane::BootValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/trane/boot_validator.rb

Class Method Summary collapse

Class Method Details

.validate!(registry) ⇒ Object

Validate referential integrity of the registry. Ensures that all representation references in operations exist, and all error keys referenced by operations are registered. Consumes the precomputed errors_by_name index from the snapshot.

Parameters:

  • registry (Module)

    Trane::Registry

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/trane/boot_validator.rb', line 12

def self.validate!(registry)
  errors         = []
  errors_by_name = registry.errors_by_name

  registry.operations.each do |op_name, op|
    op.responses.each do |status, resp|
      resp.fields.each do |field|
        errors.concat(validate_field_references(field, registry, context: "operation :#{op_name} response #{status}"))
      end
    end

    op.error_keys.each do |key|
      key_str = key.to_s
      next if errors_by_name.key?(key_str)

      errors << "operation :#{op_name} references error :#{key}, but no such error is registered"
    end
  end

  return if errors.empty?

  raise Trane::Error, "Trane boot validation failed:\n  #{errors.join("\n  ")}"
end