A section in a .ini file
# File lib/puppet/util/inifile.rb, line 18 def initialize(name, file) @name = name @file = file @dirty = false @entries = [] end
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
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 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
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 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
Should only be used internally
# File lib/puppet/util/inifile.rb, line 32 def mark_clean @dirty = false end