Class Puppet::Util::IniConfig::Section
In: lib/puppet/util/inifile.rb
Parent: Object

A section in a .ini file

Methods

[]   []=   add_line   dirty?   format   mark_clean   new  

Attributes

file  [R] 
name  [R] 

Public Class methods

[Source]

    # File lib/puppet/util/inifile.rb, line 18
18:         def initialize(name, file)
19:             @name = name
20:             @file = file
21:             @dirty = false
22:             @entries = []
23:         end

Public Instance methods

Return the value associated with KEY. If no such entry exists, return nil

[Source]

    # File lib/puppet/util/inifile.rb, line 57
57:         def [](key)
58:             entry = find_entry(key)
59:             if entry.nil?
60:                 return nil
61:             end
62:             return entry[1]
63:         end

Set the entry ‘key=value’. If no entry with the given key exists, one is appended to teh end of the section

[Source]

    # File lib/puppet/util/inifile.rb, line 45
45:         def []=(key, value)
46:             entry = find_entry(key)
47:             @dirty = true
48:             if entry.nil?
49:                 @entries << [key, value]
50:             else
51:                 entry[1] = value
52:             end
53:         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

[Source]

    # File lib/puppet/util/inifile.rb, line 39
39:         def add_line(line)
40:             @entries << line
41:         end

Has this section been modified since it‘s been read in or written back to disk

[Source]

    # File lib/puppet/util/inifile.rb, line 27
27:         def dirty?
28:             @dirty
29:         end

Format the section as text in the way it should be written to file

[Source]

    # File lib/puppet/util/inifile.rb, line 67
67:         def format
68:             text = "[#{name}]\n"
69:             @entries.each do |entry|
70:                 if entry.is_a?(Array)
71:                     key, value = entry
72:                     unless value.nil?
73:                         text << "#{key}=#{value}\n"
74:                     end
75:                 else
76:                     text << entry
77:                 end
78:             end
79:             return text
80:         end

Should only be used internally

[Source]

    # File lib/puppet/util/inifile.rb, line 32
32:         def mark_clean
33:             @dirty = false
34:         end

[Validate]