Class: AbideDevUtils::CEM::Generate::Reference::ControlMarkdown

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

Overview

Generates markdown for a control

Instance Method Summary collapse

Constructor Details

#initialize(control, md, strings, module_name, framework, formatter: nil, opts: {}) ⇒ ControlMarkdown

Returns a new instance of ControlMarkdown.



243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/abide_dev_utils/cem/generate/reference.rb', line 243

def initialize(control, md, strings, module_name, framework, formatter: nil, opts: {})
  @control = control
  @md = md
  @strings = strings
  @module_name = module_name
  @framework = framework
  @formatter = formatter.nil? ? TypeExprValueFormatter : formatter
  @opts = opts
  @valid_level = []
  @valid_profile = []
  @control_data = {}
end

Instance Method Details

#generate!Object



256
257
258
259
260
261
262
263
264
265
# File 'lib/abide_dev_utils/cem/generate/reference.rb', line 256

def generate!
  heading_builder
  control_params_builder
  control_levels_builder
  control_profiles_builder
  config_example_builder
  control_alternate_ids_builder
  dependent_controls_builder
  resource_reference_builder
end

#verify_profile_and_level_selectionsObject

This function act as a filter for controls based on the profile and level selections. There are few scanarios that can happen:

  1. If no selections are made for profile or level, then all profiles and levels of control will be selected.

  2. If selections are made for profile, then only the selected profile and all levels of control will be selected.

  3. If selections are made for level, then only the selected level and all profiles of control will be selected.

This function adds in some runtime overhead because we’re checking each control’s level and profile which is what we’re going to be doing later when building the level and profile markdown, but this is necessary to ensure that the reference.md is generated the way we want it to be.



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/abide_dev_utils/cem/generate/reference.rb', line 275

def verify_profile_and_level_selections
  return true if @opts[:select_profile].nil? && @opts[:select_level].nil?

  if @opts[:select_profile].nil? && !@opts[:select_level].nil?
    @control.levels.each do |level|
      @valid_level << level if select_control_level(level)
    end

    return true unless @valid_level.empty?
  elsif !@opts[:select_profile].nil? && @opts[:select_level].nil?
    @control.profiles.each do |profile|
      @valid_profile << profile if select_control_profile(profile)
    end

    return true unless @valid_profile.empty?
  elsif !@opts[:select_profile].nil? && !@opts[:select_level].nil?
    @control.levels.each do |level|
      @valid_level << level if select_control_level(level)
    end

    @control.profiles.each do |profile|
      @valid_profile << profile if select_control_profile(profile)
    end

    # As long as there are valid profiles and levels for the control at this stage, all is good
    !@valid_level.empty? && !@valid_profile.empty?
  end
end