Module: Hecks::Translation::Audit::UnfedReport

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

Overview

New-era attributes that nothing feeds: absent from every translated state, produced by no rule, and carrying no default. A report, not a violation — the remedy is a default: on the attribute, and the loud refusal for a REQUIRED one comes from Layer 1 the moment an invariant reads it.

Instance Method Summary collapse

Instance Method Details

#dig_path(state, path) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/hecks/translation/audit/unfed_report.rb', line 30

def dig_path(state, path)
  return nil if state.nil?

  path.to_s.split(".").reduce(state) do |node, segment|
    break nil unless node.is_a?(Hash)

    node[segment] || node[segment.to_sym]
  end
end

#unfed(aggregate, declared, after) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hecks/translation/audit/unfed_report.rb', line 10

def unfed(aggregate, declared, after)
  fed = if declared
          (declared.renames.values.map(&:to_s) +
           declared.moves.map(&:to) +
           declared.converts.map(&:to) +
           declared.computes.map(&:to)).map { |path| path.to_s.split(".").first }
        else
          []
        end
  aggregate.attributes.filter_map do |attribute|
    name = attribute.name.to_s
    next if fed.include?(name)
    next unless attribute.default.nil?
    next if after.any? { |_, state| !dig_path(state, name).nil? }
    next if after.empty?

    name
  end
end