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.

Parameters:

  • value_converter (Proc)

    a function that will convert strings into ruby types



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

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.

Parameters:

  • file (String, File)

    pointer to the file whose text we are parsing

  • text (String)

    the actual text of the inifile to be parsed

  • allowed_section_names (Array) (defaults to: [])

    an optional array of accepted section names; if this list is non-empty, sections outside of it will raise an error.

Returns:

  • A Struct with a sections array representing each configuration section



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

def parse_file(file, text, allowed_section_names = [])
  result = Conf.new
  unless 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