Method: Inspec::Control#to_ruby

Defined in:
lib/inspec/objects/control.rb

#to_rubyObject

rubocop:disable Metrics/AbcSize



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/inspec/objects/control.rb', line 30

def to_ruby # rubocop:disable Metrics/AbcSize
  res = ["control #{id.inspect} do"]
  res.push "  title #{title.inspect}" unless title.to_s.empty?
  descriptions.each do |label, text|
    if label == :default
      next if text.nil? || (text == "") # don't render empty/nil desc
      res.push "  desc  #{prettyprint_text(text, 2)}"
    else
      res.push "  desc  #{label.to_s.inspect}, #{prettyprint_text(text, 2)}"
    end
  end
  res.push "  impact #{impact}" unless impact.nil?
  tags.each { |t| res.push(indent(t.to_ruby, 2)) }
  refs.each { |t| res.push("  ref   #{print_ref(t)}") }
  res.push "  only_if { #{only_if} }" if only_if
  tests.each { |t| res.push(indent(t.to_ruby, 2)) }
  res.push "end"
  res.join("\n")
end