Class: Inspec::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/objects/control.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeControl

Returns a new instance of Control.



9
10
11
12
13
14
15
16
# File 'lib/inspec/objects/control.rb', line 9

def initialize
  @tests = []
  @tags = []
  @refs = []
  @descriptions = {}

  Inspec.deprecate(:object_classes, "The Inspec::Control class is deprecated. Use the Inspec::Object::Control class from the inspec-objects Ruby library.")
end

Instance Attribute Details

#descriptionsObject

Returns the value of attribute descriptions.



8
9
10
# File 'lib/inspec/objects/control.rb', line 8

def descriptions
  @descriptions
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/inspec/objects/control.rb', line 8

def id
  @id
end

#impactObject

Returns the value of attribute impact.



8
9
10
# File 'lib/inspec/objects/control.rb', line 8

def impact
  @impact
end

#only_ifObject

Returns the value of attribute only_if.



8
9
10
# File 'lib/inspec/objects/control.rb', line 8

def only_if
  @only_if
end

#refsObject

Returns the value of attribute refs.



8
9
10
# File 'lib/inspec/objects/control.rb', line 8

def refs
  @refs
end

#tagsObject

Returns the value of attribute tags.



8
9
10
# File 'lib/inspec/objects/control.rb', line 8

def tags
  @tags
end

#testsObject

Returns the value of attribute tests.



8
9
10
# File 'lib/inspec/objects/control.rb', line 8

def tests
  @tests
end

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/inspec/objects/control.rb', line 8

def title
  @title
end

Instance Method Details

#add_tag(t) ⇒ Object



22
23
24
# File 'lib/inspec/objects/control.rb', line 22

def add_tag(t)
  @tags.push(t)
end

#add_test(t) ⇒ Object



18
19
20
# File 'lib/inspec/objects/control.rb', line 18

def add_test(t)
  @tests.push(t)
end

#to_hashObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/inspec/objects/control.rb', line 26

def to_hash
  {
    id: id,
    title: title,
    descriptions: descriptions,
    impact: impact,
    tests: tests.map(&:to_hash),
    tags: tags.map(&:to_hash),
  }
end

#to_rubyObject

rubocop:disable Metrics/AbcSize



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/inspec/objects/control.rb', line 37

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