From 8d1fdc5c29d70027b0f1859145ced5ebb266cf9c Mon Sep 17 00:00:00 2001 From: Chris Price Date: Wed, 19 Sep 2012 15:42:16 -0700 Subject: Allow overriding separator string between key/val pairs This introduces a new parameter, 'key_val_separator', which can be set in order to override the string that is used as a separator between the key/value pair of a setting line. The default is ' = ', but you could set the param to '=' if you don't want to include whitespace in your settings file. --- lib/puppet/util/ini_file.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 4fe4169..36bc8a6 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -8,8 +8,9 @@ module Util SECTION_REGEX = /^\s*\[([\w\d\.\\\/\-\:]+)\]\s*$/ SETTING_REGEX = /^\s*([\w\d\.\\\/\-]+)\s*=\s*([\S]+)\s*$/ - def initialize(path) + def initialize(path, key_val_separator = ' = ') @path = path + @key_val_separator = key_val_separator @section_names = [] @sections_hash = {} if File.file?(@path) @@ -56,7 +57,7 @@ module Util end section.additional_settings.each_pair do |key, value| - fh.puts("#{key} = #{value}") + fh.puts("#{key}#{@key_val_separator}#{value}") end end end @@ -106,7 +107,7 @@ module Util (section.start_line..section.end_line).each do |line_num| if (match = SETTING_REGEX.match(lines[line_num])) if (match[1] == setting) - lines[line_num] = "#{setting} = #{value}" + lines[line_num] = "#{setting}#{@key_val_separator}#{value}" end end end -- cgit v1.2.3