diff options
author | Chris Price <chris@puppetlabs.com> | 2012-10-17 13:27:28 -0700 |
---|---|---|
committer | Chris Price <chris@puppetlabs.com> | 2012-10-17 13:27:28 -0700 |
commit | cda30a6ab9b6fa673ead091ab0b130cbc6e75dbc (patch) | |
tree | 17a5bb35c8861a745786105eeaee2e7d8479e711 /lib/puppet/util/ini_file/section.rb | |
parent | 1106d70e881028ee2dfa476307444780c9c4cbaa (diff) | |
download | puppet-inifile-cda30a6ab9b6fa673ead091ab0b130cbc6e75dbc.tar.gz puppet-inifile-cda30a6ab9b6fa673ead091ab0b130cbc6e75dbc.tar.bz2 |
Minor tweaks to handling of removing settings
This commit makes some minor changes to how we handle removing
settings. In particular, it updates all of the line numbers
of the various 'section' objects to correspond to the new
state of the world based on the removal of a line that appeared
before them.
Also adds one more test related to setting removal.
Diffstat (limited to 'lib/puppet/util/ini_file/section.rb')
-rw-r--r-- | lib/puppet/util/ini_file/section.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/puppet/util/ini_file/section.rb b/lib/puppet/util/ini_file/section.rb index e192d5b..16f19d3 100644 --- a/lib/puppet/util/ini_file/section.rb +++ b/lib/puppet/util/ini_file/section.rb @@ -25,13 +25,29 @@ class IniFile end def remove_existing_setting(setting_name) - @existing_settings.delete(setting_name) + if (@existing_settings.delete(setting_name)) + if @end_line + @end_line = @end_line - 1 + end + end end def set_additional_setting(setting_name, value) @additional_settings[setting_name] = value end + # Decrement the start and end line numbers for the section (if they are + # defined); this is intended to be called when a setting is removed + # from a section that comes before this section in the ini file. + def decrement_line_nums() + if @start_line + @start_line = @start_line - 1 + end + if @end_line + @end_line = @end_line - 1 + end + end + end end end |