Class: Inspec::Object::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
Returns a new instance of EachLoop.
5
6
7
8
9
|
# File 'lib/inspec/objects/each_loop.rb', line 5
def initialize
super
@tests = []
@variables = []
end
|
Instance Attribute Details
Returns the value of attribute tests.
4
5
6
|
# File 'lib/inspec/objects/each_loop.rb', line 4
def tests
@tests
end
|
#variables ⇒ Object
Returns the value of attribute variables.
3
4
5
|
# File 'lib/inspec/objects/each_loop.rb', line 3
def variables
@variables
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
|
18
19
20
|
# File 'lib/inspec/objects/each_loop.rb', line 18
def negate!
@tests.each(&:negate!)
end
|
22
23
24
|
# File 'lib/inspec/objects/each_loop.rb', line 22
def to_hash
{ qualifier: qualifier, test: @test }
end
|
26
27
28
29
30
31
32
|
# File 'lib/inspec/objects/each_loop.rb', line 26
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
|