From c2c26de9b10c3675e1044d5571e47e195a5d0167 Mon Sep 17 00:00:00 2001 From: Chris Price Date: Sat, 20 Oct 2012 00:08:06 -0700 Subject: Respect indentation / spacing for existing sections and settings This commit adds some cosmetic functionality. The main two improvements are: * We'll now pay attention to indentation within existing sections, and when we write new settings or update existing ones, we'll match the existing indentation. * When modifying existing settings, the regex now captures a greater portion of the original line and preserves it. Basically, the original whitespacing in the line should remain intact and only the value should be modified. --- lib/puppet/util/ini_file/section.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (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 16f19d3..c565872 100644 --- a/lib/puppet/util/ini_file/section.rb +++ b/lib/puppet/util/ini_file/section.rb @@ -2,15 +2,16 @@ module Puppet module Util class IniFile class Section - def initialize(name, start_line, end_line, settings) + def initialize(name, start_line, end_line, settings, indentation) @name = name @start_line = start_line @end_line = end_line @existing_settings = settings.nil? ? {} : settings @additional_settings = {} + @indentation = indentation end - attr_reader :name, :start_line, :end_line, :additional_settings + attr_reader :name, :start_line, :end_line, :additional_settings, :indentation def get_value(setting_name) @existing_settings[setting_name] || @additional_settings[setting_name] -- cgit v1.2.3