Module: Hecks::Translation::Audit::LayerOne

Included in:
Hecks::Translation::Audit
Defined in:
lib/hecks/translation/audit/layer_one.rb

Overview

Layer 1 — from the bluebook alone: every translated state must pass the new era's types, value-object invariants, and lifecycle. This is also where a NEW, stricter invariant that old records violate surfaces — there is no "grandfather old records" construct, and the remedy is relaxing the invariant or explicit remediation, never a translation rule.

Instance Method Summary collapse

Instance Method Details

#layer_one!(violations, aggregate, after) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hecks/translation/audit/layer_one.rb', line 15

def layer_one!(violations, aggregate, after)
  after.each do |id, state|
    begin
      symbolized = JSON.parse(JSON.generate(state), symbolize_names: true)
      instance = Runtime::Instance.new(aggregate: aggregate, id: id, state: symbolized)
      lifecycle = aggregate.lifecycle
      next unless lifecycle

      held = instance[lifecycle.field]
      allowed = lifecycle.states | [lifecycle.default]
      unless held.nil? || allowed.include?(held)
        violations << "#{aggregate.name}##{id}: #{lifecycle.field} is #{held.inspect}, " \
                      "a state this era's lifecycle never reaches"
      end
    rescue Runtime::InvariantViolation, Runtime::TypeMismatch => error
      violations << "#{aggregate.name}##{id}: #{error.message}"
    end
  end
end