From a45ab6593035cfbbd4cbcb535a8b8324b212ef4e Mon Sep 17 00:00:00 2001 From: Chris Price Date: Fri, 26 Oct 2012 17:24:37 -0700 Subject: Add detection for commented versions of settings This commit adds support for detecting commented versions of settings in an existing version of an inifile. If you are setting a value for a setting that isn't currently set in the file, but a commented version is found, then we add the new setting immediately following the commented version, rather than at the end of the section. --- lib/puppet/util/ini_file/section.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/puppet/util/ini_file/section.rb') diff --git a/lib/puppet/util/ini_file/section.rb b/lib/puppet/util/ini_file/section.rb index d7ff159..ba1a783 100644 --- a/lib/puppet/util/ini_file/section.rb +++ b/lib/puppet/util/ini_file/section.rb @@ -52,6 +52,19 @@ class IniFile end end + # This is a hacky method; it's basically called when we need to insert + # a new setting but we don't want it to appear at the very end of the + # section. Instead we hack it into the existing settings list and + # increment our end_line number--this assumes that the caller (`ini_file`) + # is doing some babysitting w/rt the other sections and the actual data + # of the lines. + def insert_inline_setting(setting_name, value) + @existing_settings[setting_name] = value + if @end_line + @end_line = @end_line + 1 + end + end + def set_additional_setting(setting_name, value) @additional_settings[setting_name] = value end @@ -68,6 +81,18 @@ class IniFile end end + # Increment the start and end line numbers for the section (if they are + # defined); this is intended to be called when an inline setting is added + # to a section that comes before this section in the ini file. + def increment_line_nums() + if @start_line + @start_line = @start_line + 1 + end + if @end_line + @end_line = @end_line + 1 + end + end + end end end -- cgit v1.2.3