Sha256: 43be4b73f75331a303692c080b09c0ec7cec90900841e6856278e54a6a29c402

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

require 'inspec/reporters/base'
require 'inspec/reporters/cli'
require 'inspec/reporters/json'
require 'inspec/reporters/json_min'
require 'inspec/reporters/junit'

module Inspec::Reporters
  def self.render(reporter, run_data)
    name, config = reporter.dup
    config[:run_data] = run_data
    case name
    when 'cli'
      reporter = Inspec::Reporters::CLI.new(config)
    when 'json'
      reporter = Inspec::Reporters::Json.new(config)
    when 'json-min'
      reporter = Inspec::Reporters::JsonMin.new(config)
    when 'junit'
      reporter = Inspec::Reporters::Junit.new(config)
    else
      raise NotImplementedError, "'#{name}' is not a valid reporter type."
    end

    reporter.render
    output = reporter.rendered_output

    if config['file']
      File.write(config['file'], output)
    elsif config['stdout'] == true
      print output
      STDOUT.flush
    end
  end

  def self.report(reporter, run_data)
    name, config = reporter.dup
    config[:run_data] = run_data
    case name
    when 'json'
      reporter = Inspec::Reporters::Json.new(config)
    when 'json-min'
      reporter = Inspec::Reporters::JsonMin.new(config)
    else
      # use base run_data hash for any other report
      return run_data
    end

    reporter.report
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
inspec-2.0.32 lib/inspec/reporters.rb
inspec-2.0.17 lib/inspec/reporters.rb
inspec-1.51.15 lib/inspec/reporters.rb