Class: Inspec::Object::Control
- Inherits:
-
Object
- Object
- Inspec::Object::Control
- Defined in:
- lib/inspec/objects/control.rb
Instance Attribute Summary collapse
-
#descriptions ⇒ Object
Returns the value of attribute descriptions.
-
#header ⇒ Object
Returns the value of attribute header.
-
#id ⇒ Object
Returns the value of attribute id.
-
#impact ⇒ Object
Returns the value of attribute impact.
-
#only_if ⇒ Object
Returns the value of attribute only_if.
-
#post_body ⇒ Object
Returns the value of attribute post_body.
-
#refs ⇒ Object
Returns the value of attribute refs.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#tests ⇒ Object
Returns the value of attribute tests.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #add_header(header) ⇒ Object
- #add_post_body(post_body) ⇒ Object
- #add_tag(t) ⇒ Object
- #add_test(t) ⇒ Object
-
#initialize ⇒ Control
constructor
A new instance of Control.
- #to_hash ⇒ Object
- #to_ruby ⇒ Object
Constructor Details
#initialize ⇒ Control
Returns a new instance of Control.
6 7 8 9 10 11 12 13 |
# File 'lib/inspec/objects/control.rb', line 6 def initialize @header = "" @tests = [] @tags = [] @refs = [] @descriptions = {} @post_body = "" end |
Instance Attribute Details
#descriptions ⇒ Object
Returns the value of attribute descriptions.
5 6 7 |
# File 'lib/inspec/objects/control.rb', line 5 def descriptions @descriptions end |
#header ⇒ Object
Returns the value of attribute header.
5 6 7 |
# File 'lib/inspec/objects/control.rb', line 5 def header @header end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/inspec/objects/control.rb', line 5 def id @id end |
#impact ⇒ Object
Returns the value of attribute impact.
5 6 7 |
# File 'lib/inspec/objects/control.rb', line 5 def impact @impact end |
#only_if ⇒ Object
Returns the value of attribute only_if.
5 6 7 |
# File 'lib/inspec/objects/control.rb', line 5 def only_if @only_if end |
#post_body ⇒ Object
Returns the value of attribute post_body.
5 6 7 |
# File 'lib/inspec/objects/control.rb', line 5 def post_body @post_body end |
#refs ⇒ Object
Returns the value of attribute refs.
5 6 7 |
# File 'lib/inspec/objects/control.rb', line 5 def refs @refs end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/inspec/objects/control.rb', line 5 def @tags end |
#tests ⇒ Object
Returns the value of attribute tests.
5 6 7 |
# File 'lib/inspec/objects/control.rb', line 5 def tests @tests end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/inspec/objects/control.rb', line 5 def title @title end |
Instance Method Details
#add_header(header) ⇒ Object
15 16 17 |
# File 'lib/inspec/objects/control.rb', line 15 def add_header(header) @header = header end |
#add_post_body(post_body) ⇒ Object
27 28 29 |
# File 'lib/inspec/objects/control.rb', line 27 def add_post_body(post_body) @post_body = post_body end |
#add_tag(t) ⇒ Object
23 24 25 |
# File 'lib/inspec/objects/control.rb', line 23 def add_tag(t) @tags.push(t) end |
#add_test(t) ⇒ Object
19 20 21 |
# File 'lib/inspec/objects/control.rb', line 19 def add_test(t) @tests.push(t) end |
#to_hash ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/inspec/objects/control.rb', line 31 def to_hash { header: header, id: id, title: title, descriptions: descriptions, impact: impact, tests: tests.map(&:to_hash), tags: .map(&:to_hash), post_body: post_body, } end |
#to_ruby ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/inspec/objects/control.rb', line 44 def to_ruby res = [] res.push header unless header.nil? || header.empty? res.push "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? .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(indent(post_body, 2)) unless post_body.nil? || post_body.empty? res.push "end" res.join("\n") end |