Method: Inspec::Profile#initialize

Defined in:
lib/inspec/profile.rb

#initialize(options = nil) ⇒ Profile

Returns a new instance of Profile.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/inspec/profile.rb', line 21

def initialize(options = nil)
  @options = options || {}

  @params = {}
  @logger = options[:logger] || Logger.new(nil)

  @path = @options[:path]
  fail 'Cannot read an empty path.' if @path.nil? || @path.empty?
  fail "Cannot find directory #{@path}" unless File.directory?(@path)

  @metadata = 
  @params = @metadata.params
  # use the id from parameter, name or fallback to nil
  @profile_id = options[:id] || params[:name] || nil

  @params[:rules] = rules = {}
  @runner = Runner.new(
    id: @profile_id,
    backend: :mock,
  )
  @runner.add_tests([@path], @options)
  @runner.rules.each do |id, rule|
    file = rule.instance_variable_get(:@__file)
    rules[file] ||= {}
    rules[file][id] = {
      title: rule.title,
      desc: rule.desc,
      impact: rule.impact,
      checks: rule.instance_variable_get(:@checks),
      code: rule.instance_variable_get(:@__code),
      group_title: rule.instance_variable_get(:@__group_title),
    }
  end
end