Class: AbideDevUtils::CEM::Generate::Reference::MarkdownGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/cem/generate/reference.rb

Overview

Generates a markdown reference doc

Constant Summary collapse

SPECIAL_CONTROL_IDS =
%w[dependent cem_options cem_protected].freeze

Instance Method Summary collapse

Constructor Details

#initialize(benchmarks, module_name, file: 'REFERENCE.md') ⇒ MarkdownGenerator

Returns a new instance of MarkdownGenerator.



64
65
66
67
68
69
# File 'lib/abide_dev_utils/cem/generate/reference.rb', line 64

def initialize(benchmarks, module_name, file: 'REFERENCE.md')
  @benchmarks = benchmarks
  @module_name = module_name
  @file = file
  @md = AbideDevUtils::Markdown.new(@file)
end

Instance Method Details

#generate(doc_title = 'Reference') ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/abide_dev_utils/cem/generate/reference.rb', line 71

def generate(doc_title = 'Reference')
  md.add_title(doc_title)
  benchmarks.each do |benchmark|
    progress_bar = AbideDevUtils::Output.progress(title: "Generating Markdown for #{benchmark.title_key}",
                                                  total: benchmark.controls.length)
    md.add_h1(benchmark.title_key)
    benchmark.controls.each do |control|
      next if SPECIAL_CONTROL_IDS.include? control.id
      next if benchmark.framework == 'stig' && control.id_map_type != 'vulnid'

      control_md = ControlMarkdown.new(control, @md, @module_name, benchmark.framework)
      control_md.generate!
      progress_bar.increment
    rescue StandardError => e
      raise "Failed to generate markdown for control #{control.id}. Original message: #{e.message}"
    end
  end
  AbideDevUtils::Output.simple("Saving markdown to #{@file}")
  md.to_file
end