@api private
# File lib/puppet/settings/ini_file.rb, line 32 def append(line) line.previous = @lines.last @lines << line end
# File lib/puppet/settings/ini_file.rb, line 37 def insert_after(line, new_line) new_line.previous = line insertion_point = @lines.index(line) @lines.insert(insertion_point + 1, new_line) if @lines.length > insertion_point + 2 @lines[insertion_point + 2].previous = new_line end end
# File lib/puppet/settings/ini_file.rb, line 61 def lines_in(section_name) section_lines = [] current_section_name = DEFAULT_SECTION_NAME @lines.each do |line| if line.is_a?(SectionLine) current_section_name = line.name elsif current_section_name == section_name section_lines << line end end section_lines end
# File lib/puppet/settings/ini_file.rb, line 51 def section_line(name) section_lines.find { |section| section.name == name } end
# File lib/puppet/settings/ini_file.rb, line 47 def section_lines @lines.select { |line| line.is_a?(SectionLine) } end
# File lib/puppet/settings/ini_file.rb, line 55 def setting(section, name) settings_in(lines_in(section)).find do |line| line.name == name end end
# File lib/puppet/settings/ini_file.rb, line 75 def settings_in(lines) lines.select { |line| line.is_a?(SettingLine) } end
# File lib/puppet/settings/ini_file.rb, line 79 def write(fh) fh.truncate(0) fh.rewind @lines.each do |line| line.write(fh) end fh.flush end
# File lib/puppet/settings/ini_file.rb, line 28 def initialize(lines = []) @lines = lines end
# File lib/puppet/settings/ini_file.rb, line 12 def self.parse(config_fh) config = new([DefaultSection.new]) config_fh.each_line do |line| case line when /^(\s*)\[(\w+)\](\s*)$/ config.append(SectionLine.new($1, $2, $3)) when /^(\s*)(\w+)(\s*=\s*)(.*?)(\s*)$/ config.append(SettingLine.new($1, $2, $3, $4, $5)) else config.append(Line.new(line)) end end config end
# File lib/puppet/settings/ini_file.rb, line 5 def self.update(config_fh, &block) config = parse(config_fh) manipulator = Manipulator.new(config) yield manipulator config.write(config_fh) end