class Puppet::Util::IniConfig::Section
A section in a .ini file
Attributes
destroy[W]
entries[R]
file[R]
name[R]
Public Class Methods
new(name, file)
click to toggle source
# File lib/puppet/util/inifile.rb 21 def initialize(name, file) 22 @name = name 23 @file = file 24 @dirty = false 25 @entries = [] 26 @destroy = false 27 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 73 def [](key) 74 entry = find_entry(key) 75 return(entry.nil? ? nil : entry[1]) 76 end
[]=(key, value)
click to toggle source
Set the entry 'key=value'. If no entry with the given key exists, one is appended to the end of the section
# File lib/puppet/util/inifile.rb 61 def []=(key, value) 62 entry = find_entry(key) 63 @dirty = true 64 if entry.nil? 65 @entries << [key, value] 66 else 67 entry[1] = value 68 end 69 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 55 def add_line(line) 56 @entries << line 57 end
destroy?()
click to toggle source
Should the file be destroyed?
# File lib/puppet/util/inifile.rb 48 def destroy? 49 @destroy 50 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 34 def dirty? 35 @dirty or @destroy 36 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 80 def format 81 if @destroy 82 text = String.new 83 else 84 text = "[#{name}]\n" 85 @entries.each do |entry| 86 if entry.is_a?(Array) 87 key, value = entry 88 text << "#{key}=#{value}\n" unless value.nil? 89 else 90 text << entry 91 end 92 end 93 end 94 text 95 end
mark_clean()
click to toggle source
Should only be used internally
# File lib/puppet/util/inifile.rb 43 def mark_clean 44 @dirty = false 45 end
mark_dirty()
click to toggle source
# File lib/puppet/util/inifile.rb 38 def mark_dirty 39 @dirty = true 40 end
Private Instance Methods
find_entry(key)
click to toggle source
# File lib/puppet/util/inifile.rb 98 def find_entry(key) 99 @entries.each do |entry| 100 return entry if entry.is_a?(Array) && entry[0] == key 101 end 102 nil 103 end