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 20 def initialize(name, file) 21 @name = name 22 @file = file 23 @dirty = false 24 @entries = [] 25 @destroy = false 26 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 72 def [](key) 73 entry = find_entry(key) 74 return(entry.nil? ? nil : entry[1]) 75 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 60 def []=(key, value) 61 entry = find_entry(key) 62 @dirty = true 63 if entry.nil? 64 @entries << [key, value] 65 else 66 entry[1] = value 67 end 68 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 54 def add_line(line) 55 @entries << line 56 end
destroy?()
click to toggle source
Should the file be destroyed?
# File lib/puppet/util/inifile.rb 47 def destroy? 48 @destroy 49 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 33 def dirty? 34 @dirty or @destroy 35 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 79 def format 80 if @destroy 81 text = "" 82 else 83 text = "[#{name}]\n" 84 @entries.each do |entry| 85 if entry.is_a?(Array) 86 key, value = entry 87 text << "#{key}=#{value}\n" unless value.nil? 88 else 89 text << entry 90 end 91 end 92 end 93 text 94 end
mark_clean()
click to toggle source
Should only be used internally
# File lib/puppet/util/inifile.rb 42 def mark_clean 43 @dirty = false 44 end
mark_dirty()
click to toggle source
# File lib/puppet/util/inifile.rb 37 def mark_dirty 38 @dirty = true 39 end
Private Instance Methods
find_entry(key)
click to toggle source
# File lib/puppet/util/inifile.rb 97 def find_entry(key) 98 @entries.each do |entry| 99 return entry if entry.is_a?(Array) && entry[0] == key 100 end 101 nil 102 end