Class: Inspec::EachLoop

Inherits:
List show all
Defined in:
lib/inspec/objects/each_loop.rb

Instance Attribute Summary collapse

Attributes inherited from Value

#qualifier, #skip, #variable

Instance Method Summary collapse

Methods inherited from List

#map

Methods inherited from Value

#name_variable

Methods included from RubyHelper

#ruby_qualifier

Constructor Details

#initializeEachLoop

Returns a new instance of EachLoop.



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

def initialize
  super
  @tests = []
  @variables = []

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

Instance Attribute Details

#testsObject

Returns the value of attribute tests.



9
10
11
# File 'lib/inspec/objects/each_loop.rb', line 9

def tests
  @tests
end

#variablesObject (readonly)

Returns the value of attribute variables.



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

def variables
  @variables
end

Instance Method Details

#add_test(t = nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/inspec/objects/each_loop.rb', line 18

def add_test(t = nil)
  t ||= Test.new
  t.qualifier[0] = ["entry"]
  @tests.push(t)
  t
end

#negate!Object



25
26
27
# File 'lib/inspec/objects/each_loop.rb', line 25

def negate!
  @tests.each(&:negate!)
end

#to_hashObject



29
30
31
# File 'lib/inspec/objects/each_loop.rb', line 29

def to_hash
  { qualifier: qualifier, test: @test }
end

#to_rubyObject



33
34
35
36
37
38
39
# File 'lib/inspec/objects/each_loop.rb', line 33

def to_ruby
  vars = variables.map(&:to_ruby).join("\n")
  vars += "\n" unless vars.empty?
  obj = super
  all_tests = @tests.map(&:to_ruby).join("\n").gsub("\n", "\n  ")
  format("%s%s.each do |entry|\n  %s\nend", vars, obj, all_tests)
end