Class: Dogfood::DSL::AuditReport

Inherits:
Object
  • Object
show all
Defined in:
lib/dogfood/dsl/audit_report.rb

Overview

Builds a pure-data audit report from a compiled AST and renders it in one of three formats:

:text     -> the classic box-drawing tree + tables (default; regression
           target is EXAMPLES/explain_output.txt)
:markdown -> GitHub-flavored Markdown (headings, bullets, tables)
:json     -> machine-readable; Ruby symbols tagged as {"__sym__": "..."}

The computation (path enumeration, gap detection, branch-weight and step resolution collection) runs once in AuditReport.build; formatters only read the resulting Hash and emit strings.

Defined Under Namespace

Classes: JsonFormatter, MarkdownFormatter, TextFormatter

Constant Summary collapse

MAX_PATHS =
50

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast, pack: nil, max_paths: MAX_PATHS) ⇒ AuditReport

Returns a new instance of AuditReport.



34
35
36
37
38
# File 'lib/dogfood/dsl/audit_report.rb', line 34

def initialize(ast, pack: nil, max_paths: MAX_PATHS)
  @ast = ast
  @pack = pack
  @max_paths = max_paths
end

Class Method Details

.build(ast, pack: nil, max_paths: MAX_PATHS) ⇒ Object



20
21
22
# File 'lib/dogfood/dsl/audit_report.rb', line 20

def self.build(ast, pack: nil, max_paths: MAX_PATHS)
  new(ast, pack: pack, max_paths: max_paths).build
end

.render(report, format: :text) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/dogfood/dsl/audit_report.rb', line 24

def self.render(report, format: :text)
  case format.to_sym
  when :text then TextFormatter.render(report)
  when :markdown then MarkdownFormatter.render(report)
  when :json then JsonFormatter.render(report)
  else
    raise ArgumentError, "unknown format: #{format.inspect}"
  end
end

Instance Method Details

#buildObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dogfood/dsl/audit_report.rb', line 40

def build
  paths = enumerate_paths
  {
    scenario: {
      name: @ast[:name],
      title: @ast[:title],
      stages: @ast[:stages].map { |s| s[:stage] },
      resume: @ast[:resume],
      delays: @ast[:delays]
    },
    tree: build_tree,
    tree_text: ExplainRenderer.new(@ast).render,
    branches: build_branches,
    conditionals: collect_conditional_probs,
    paths: paths,
    paths_truncated: paths.length > @max_paths,
    paths_total: paths.length,
    max_paths: @max_paths,
    gaps: detect_gaps,
    resolution: build_resolution
  }
end