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

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



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

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.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/puppet/settings/config_file.rb', line 15

def parse_file(file, text)
  result = {}
  count = 0

  # Default to 'main' for the section.
  section_name = :main
  result[section_name] = empty_section
  text.split(/\n/).each do |line|
    count += 1
    case line
    when /^\s*\[(\w+)\]\s*$/
      section_name = $1.intern
      fail_when_illegal_section_name(section_name, file, line)
      if result[section_name].nil?
        result[section_name] = empty_section
      end
    when /^\s*#/; next # Skip comments
    when /^\s*$/; next # Skip blanks
    when /^\s*(\w+)\s*=\s*(.*?)\s*$/ # settings
      var = $1.intern

      # We don't want to munge modes, because they're specified in octal, so we'll
      # just leave them as a String, since Puppet handles that case correctly.
      if var == :mode
        value = $2
      else
        value = @value_converter[$2]
      end

      # Check to see if this is a file argument and it has extra options
      begin
        if value.is_a?(String) and options = extract_fileinfo(value)
          value = options[:value]
          options.delete(:value)
          result[section_name][:_meta][var] = options
        end
        result[section_name][var] = value
      rescue Puppet::Error => detail
        raise Puppet::Settings::ParseError.new(detail.message, file, line, detail)
      end
    else
      raise Puppet::Settings::ParseError.new("Could not match line #{line}", file, line)
    end
  end

  result
end