Module: Chef::DSL::ReaderHelpers

Extended by:
ReaderHelpers
Included in:
ReaderHelpers, Universal
Defined in:
lib/chef/dsl/reader_helpers.rb

Instance Method Summary collapse

Instance Method Details

#parse_file(filename) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/chef/dsl/reader_helpers.rb', line 25

def parse_file(filename)
  case File.extname(filename)
  when ".toml"
    parse_toml(filename)
  when ".yaml", ".yml"
    parse_yaml(filename)
  when ".json"
    parse_json(filename)
  end
end

#parse_json(filename) ⇒ Object



36
37
38
# File 'lib/chef/dsl/reader_helpers.rb', line 36

def parse_json(filename)
  JSONCompat.parse(IO.read(filename))
end

#parse_toml(filename) ⇒ Object



40
41
42
# File 'lib/chef/dsl/reader_helpers.rb', line 40

def parse_toml(filename)
  Tomlrb.load_file(filename)
end

#parse_yaml(filename) ⇒ Object



44
45
46
# File 'lib/chef/dsl/reader_helpers.rb', line 44

def parse_yaml(filename)
  YAML.safe_load_file(filename, permitted_classes: [Date])
end