Sha256: eaee75922b4eccc5f4c671239a2e47a261e51f8c2c8ce2042593e542f7aab9cb

Contents?: true

Size: 744 Bytes

Versions: 6

Compression:

Stored size: 744 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

6 entries across 6 versions & 1 rubygems

Version Path
inspec-2.1.81 lib/inspec/objects/each_loop.rb
inspec-2.1.21 lib/inspec/objects/each_loop.rb
inspec-2.1.10 lib/inspec/objects/each_loop.rb
inspec-2.0.32 lib/inspec/objects/each_loop.rb
inspec-2.0.17 lib/inspec/objects/each_loop.rb
inspec-1.51.15 lib/inspec/objects/each_loop.rb