diff options
author | Chris Price <chris@puppetlabs.com> | 2012-10-26 17:24:37 -0700 |
---|---|---|
committer | Chris Price <chris@puppetlabs.com> | 2012-10-26 17:24:37 -0700 |
commit | a45ab6593035cfbbd4cbcb535a8b8324b212ef4e (patch) | |
tree | 8fec4645f400965c3402df673c7276d2ed012e6f /lib/puppet/util/ini_file | |
parent | 8a0d1fa1f289a5f1fc3f72cd0ebb3c52e923d024 (diff) | |
download | puppet-inifile-a45ab6593035cfbbd4cbcb535a8b8324b212ef4e.tar.gz puppet-inifile-a45ab6593035cfbbd4cbcb535a8b8324b212ef4e.tar.bz2 |
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.
Diffstat (limited to 'lib/puppet/util/ini_file')
-rw-r--r-- | lib/puppet/util/ini_file/section.rb | 25 |
1 files changed, 25 insertions, 0 deletions
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 |