A section in a .ini file
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
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 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
Should the file be destroyed?
# File lib/puppet/util/inifile.rb, line 47 def destroy? @destroy end
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 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
Should only be used internally
# File lib/puppet/util/inifile.rb, line 42 def mark_clean @dirty = false end
# File lib/puppet/util/inifile.rb, line 37 def mark_dirty @dirty = true end
# File lib/puppet/util/inifile.rb, line 20 def initialize(name, file) @name = name @file = file @dirty = false @entries = [] @destroy = false end