class Puppet::Util::IniConfig::Section

A section in a .ini file

Attributes

destroy[W]
entries[R]
file[R]
name[R]

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 72
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 60
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 54
def add_line(line)
  @entries << line
end
destroy?() click to toggle source

Should the file be destroyed?

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

Does this section need to be updated in/removed from the associated file?

@note This section is dirty if a key has been modified or if the

section has been modified so the associated file can be rewritten
without this section.
# File lib/puppet/util/inifile.rb, line 33
def dirty?
  @dirty or @destroy
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 79
def format
  if @destroy
    text = ""
  else
    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
  end
  text
end
mark_clean() click to toggle source

Should only be used internally

# File lib/puppet/util/inifile.rb, line 42
def mark_clean
  @dirty = false
end
mark_dirty() click to toggle source
# File lib/puppet/util/inifile.rb, line 37
def mark_dirty
  @dirty = true
end

Public Class Methods

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