Sha256: d4753fabfe7db385c0a0f0db5338e7fd7219401e7571feabaa9e44c347d238f2

Contents?: true

Size: 708 Bytes

Versions: 168

Compression:

Stored size: 708 Bytes

Contents

# encoding:utf-8

module Inspec
  class EachLoop < List
    attr_reader :variables
    attr_accessor :tests
    def initialize
      super
      @tests = []
      @variables = []
    end

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

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

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

    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
  end
end

Version data entries

168 entries across 168 versions & 2 rubygems

Version Path
inspec-core-4.3.2 lib/inspec/objects/each_loop.rb
inspec-4.3.2 lib/inspec/objects/each_loop.rb
inspec-core-4.2.0.preview lib/inspec/objects/each_loop.rb
inspec-4.2.0.preview lib/inspec/objects/each_loop.rb
inspec-core-4.1.4.preview lib/inspec/objects/each_loop.rb
inspec-4.1.4.preview lib/inspec/objects/each_loop.rb
inspec-core-3.9.3 lib/inspec/objects/each_loop.rb
inspec-3.9.3 lib/inspec/objects/each_loop.rb
inspec-core-3.9.0 lib/inspec/objects/each_loop.rb
inspec-3.9.0 lib/inspec/objects/each_loop.rb
inspec-core-3.7.11 lib/inspec/objects/each_loop.rb
inspec-3.7.11 lib/inspec/objects/each_loop.rb
inspec-core-3.7.1 lib/inspec/objects/each_loop.rb
inspec-3.7.1 lib/inspec/objects/each_loop.rb
inspec-core-3.6.6 lib/inspec/objects/each_loop.rb
inspec-3.6.6 lib/inspec/objects/each_loop.rb
inspec-core-3.6.4 lib/inspec/objects/each_loop.rb
inspec-3.6.4 lib/inspec/objects/each_loop.rb
inspec-core-2.3.28 lib/inspec/objects/each_loop.rb
inspec-2.3.28 lib/inspec/objects/each_loop.rb