2012-07-29 06:59:54 +02:00
|
|
|
module Puppet
|
|
|
|
module Util
|
|
|
|
class IniFile
|
|
|
|
class Section
|
2012-10-20 09:08:06 +02:00
|
|
|
def initialize(name, start_line, end_line, settings, indentation)
|
2012-07-29 06:59:54 +02:00
|
|
|
@name = name
|
|
|
|
@start_line = start_line
|
|
|
|
@end_line = end_line
|
|
|
|
@existing_settings = settings.nil? ? {} : settings
|
|
|
|
@additional_settings = {}
|
2012-10-20 09:08:06 +02:00
|
|
|
@indentation = indentation
|
2012-07-29 06:59:54 +02:00
|
|
|
end
|
|
|
|
|
2012-10-20 09:08:06 +02:00
|
|
|
attr_reader :name, :start_line, :end_line, :additional_settings, :indentation
|
2012-07-29 06:59:54 +02:00
|
|
|
|
|
|
|
def get_value(setting_name)
|
|
|
|
@existing_settings[setting_name] || @additional_settings[setting_name]
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_existing_setting?(setting_name)
|
|
|
|
@existing_settings.has_key?(setting_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_existing_setting(setting_name, value)
|
|
|
|
@existing_settings[setting_name] = value
|
|
|
|
end
|
|
|
|
|
2012-10-11 02:40:38 +02:00
|
|
|
def remove_existing_setting(setting_name)
|
2012-10-17 22:27:28 +02:00
|
|
|
if (@existing_settings.delete(setting_name))
|
|
|
|
if @end_line
|
|
|
|
@end_line = @end_line - 1
|
|
|
|
end
|
|
|
|
end
|
2012-10-11 02:40:38 +02:00
|
|
|
end
|
|
|
|
|
2012-07-29 06:59:54 +02:00
|
|
|
def set_additional_setting(setting_name, value)
|
|
|
|
@additional_settings[setting_name] = value
|
|
|
|
end
|
|
|
|
|
2012-10-17 22:27:28 +02:00
|
|
|
# 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
|
|
|
|
|
2012-07-29 06:59:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-10-11 02:40:38 +02:00
|
|
|
end
|