class Puppet::Util::IniConfig::Section

A section in a .ini file

Attributes

file[R]
name[R]

Public Class Methods

new(name, file) click to toggle source
# File lib/puppet/util/inifile.rb, line 18
def initialize(name, file)
  @name = name
  @file = file
  @dirty = false
  @entries = []
end

Public Instance Methods

[](key) click to toggle source

Return the value associated with KEY. If no such entry exists, return nil

# File lib/puppet/util/inifile.rb, line 57
def [](key)
  entry = find_entry(key)
  return(entry.nil? ? nil : entry[1])
end
[]=(key, value) click to toggle source

Set the entry ‘key=value’. If no entry with the given key exists, one is appended to teh end of the section

# File lib/puppet/util/inifile.rb, line 45
def []=(key, value)
  entry = find_entry(key)
  @dirty = true
  if entry.nil?
    @entries << [key, value]
  else
    entry[1] = value
  end
end
add_line(line) click to toggle source

Add a line of text (e.g., a comment) Such lines will be written back out in exactly the same place they were read in

# File lib/puppet/util/inifile.rb, line 39
def add_line(line)
  @entries << line
end
dirty?() click to toggle source

Has this section been modified since it’s been read in or written back to disk

# File lib/puppet/util/inifile.rb, line 27
def dirty?
  @dirty
end
format() click to toggle source

Format the section as text in the way it should be written to file

# File lib/puppet/util/inifile.rb, line 64
def format
  text = "[#{name}]\n"
  @entries.each do |entry|
    if entry.is_a?(Array)
      key, value = entry
      text << "#{key}=#{value}\n" unless value.nil?
    else
      text << entry
    end
  end
  text
end
mark_clean() click to toggle source

Should only be used internally

# File lib/puppet/util/inifile.rb, line 32
def mark_clean
  @dirty = false
end