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.



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

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

Instance Attribute Details

#testsObject

Returns the value of attribute tests.



6
7
8
# File 'lib/inspec/objects/each_loop.rb', line 6

def tests
  @tests
end

#variablesObject (readonly)

Returns the value of attribute variables.



5
6
7
# File 'lib/inspec/objects/each_loop.rb', line 5

def variables
  @variables
end

Instance Method Details

#add_test(t = nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/inspec/objects/each_loop.rb', line 13

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

#negate!Object



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

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

#to_hashObject



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

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

#to_rubyObject



28
29
30
31
32
33
34
# File 'lib/inspec/objects/each_loop.rb', line 28

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