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.



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

def initialize
  super
  @tests = []
end

Instance Attribute Details

#testsObject (readonly)

Returns the value of attribute tests.



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

def tests
  @tests
end

Instance Method Details

#add_test(t = nil) ⇒ Object



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

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

#negate!Object



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

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

#to_hashObject



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

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

#to_rubyObject



26
27
28
29
30
# File 'lib/inspec/objects/each_loop.rb', line 26

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