Method: Puppet::Util::IniConfig::PhysicalFile#parse

Defined in:
lib/puppet/util/inifile.rb

#parse(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.



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/puppet/util/inifile.rb', line 154

def parse(text)
  section = nil   # The name of the current section
  optname = nil   # The name of the last option in section
  line_num = 0

  text.each_line do |l|
    line_num += 1
    if l.match(INI_COMMENT)
      # Whitespace or comment
      if section.nil?
        @contents << l
      else
        section.add_line(l)
      end
    elsif l.match(INI_CONTINUATION) && section && optname
      # continuation line
      section[optname] += "\n#{l.chomp}"
    elsif (match = l.match(INI_SECTION_NAME))
      # section heading
      section.mark_clean if section

      section_name = match[1]

      section = add_section(section_name)
      optname = nil
    elsif (match = l.match(INI_PROPERTY))
      # the regex strips leading white space from the value, and here we strip the trailing white space as well
      key = match[1]
      val = match[2].rstrip

      if section.nil?
        raise IniParseError.new(_("Property with key %{key} outside of a section") % { key: key.inspect })
      end

      section[key] = val
      optname = key
    else
      raise IniParseError.new(_("Can't parse line '%{line}'") % { line: l.chomp }, @file, line_num)
    end
  end
  section.mark_clean unless section.nil?
end