summaryrefslogtreecommitdiff
path: root/lib/puppet/util/ini_file/section.rb
diff options
context:
space:
mode:
authorChris Price <chris@puppetlabs.com>2012-10-22 11:05:39 -0700
committerChris Price <chris@puppetlabs.com>2012-10-22 11:05:39 -0700
commit8a0d1fa1f289a5f1fc3f72cd0ebb3c52e923d024 (patch)
tree610b78ab10ae9cf0f495f71f743433ab9f11ea57 /lib/puppet/util/ini_file/section.rb
parenta5eebcfca0c1c8e8fb8130205a6ec623c8691326 (diff)
parentf0d443fed02d870965613dd174793cc1816137a2 (diff)
downloadpuppet-inifile-8a0d1fa1f289a5f1fc3f72cd0ebb3c52e923d024.tar.gz
puppet-inifile-8a0d1fa1f289a5f1fc3f72cd0ebb3c52e923d024.tar.bz2
Merge pull request #19 from cprice-puppet/feature/master/use-existing-indentation
Feature/master/use existing indentation
Diffstat (limited to 'lib/puppet/util/ini_file/section.rb')
-rw-r--r--lib/puppet/util/ini_file/section.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/puppet/util/ini_file/section.rb b/lib/puppet/util/ini_file/section.rb
index 16f19d3..d7ff159 100644
--- a/lib/puppet/util/ini_file/section.rb
+++ b/lib/puppet/util/ini_file/section.rb
@@ -2,15 +2,35 @@ module Puppet
module Util
class IniFile
class Section
- def initialize(name, start_line, end_line, settings)
+ # Some implementation details:
+ #
+ # * `name` will be set to the empty string for the 'global' section.
+ # * there will always be a 'global' section, with a `start_line` of 0,
+ # but if the file actually begins with a real section header on
+ # the first line, then the 'global' section will have an
+ # `end_line` of `nil`.
+ # * `start_line` and `end_line` will be set to `nil` for a new non-global
+ # section.
+ 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 is_global?()
+ @name == ''
+ end
+
+ def is_new_section?()
+ # a new section (global or named) will always have `end_line`
+ # set to `nil`
+ @end_line.nil?
+ end
def get_value(setting_name)
@existing_settings[setting_name] || @additional_settings[setting_name]