Method: Inspec::Resources::JsonConfig#initialize

Defined in:
lib/resources/json.rb

#initialize(path) ⇒ JsonConfig

Returns a new instance of JsonConfig.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/resources/json.rb', line 22

def initialize(path)
  @path = path
  @file = inspec.file(@path)
  @file_content = @file.content

  # check if file is available
  if !@file.file?
    skip_resource "Can't find file \"#{@conf_path}\""
    return @params = {}
  end

  # check if file is readable
  if @file_content.empty? && @file.size > 0
    skip_resource "Can't read file \"#{@conf_path}\""
    return @params = {}
  end

  @params = parse(@file_content)
end