Class: Puppet::Settings::ConfigFile Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/settings/config_file.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Parses puppet configuration files

Defined Under Namespace

Classes: Conf, Meta, Section, Setting

Constant Summary collapse

NO_META =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Meta.new(nil, nil, nil)

Instance Method Summary collapse

Constructor Details

#initialize(value_converter) ⇒ ConfigFile

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ConfigFile


12
13
14
# File 'lib/puppet/settings/config_file.rb', line 12

def initialize(value_converter)
  @value_converter = value_converter
end

Instance Method Details

#parse_file(file, text, allowed_section_names = []) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns A Struct with a sections array representing each configuration section


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/puppet/settings/config_file.rb', line 22

def parse_file(file, text, allowed_section_names = [])
  result = Conf.new
  if !allowed_section_names.empty?
    allowed_section_names << 'main' unless allowed_section_names.include?('main')
  end

  ini = Puppet::Settings::IniFile.parse(text.encode(Encoding::UTF_8))
  unique_sections_in(ini, file, allowed_section_names).each do |section_name|
    section = Section.new(section_name.to_sym)
    result.with_section(section)

    ini.lines_in(section_name).each do |line|
      if line.is_a?(Puppet::Settings::IniFile::SettingLine)
        parse_setting(line, section)
      elsif line.text !~ /^\s*#|^\s*$/
        raise Puppet::Settings::ParseError.new(_("Could not match line %{text}") % { text: line.text }, file, line.line_number)
      end
    end
  end

  result
end