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

ALLOWED_SECTION_NAMES =

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.

['main', 'master', 'agent', 'user'].freeze
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



15
16
17
# File 'lib/puppet/settings/config_file.rb', line 15

def initialize(value_converter)
  @value_converter = value_converter
end

Instance Method Details

#parse_file(file, text) ⇒ 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.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/puppet/settings/config_file.rb', line 19

def parse_file(file, text)
  result = Conf.new

  ini = Puppet::Settings::IniFile.parse(StringIO.new(text))
  unique_sections_in(ini, file).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 #{line.text}", file, line.line_number)
      end
    end
  end

  result
end