diff options
author | Stephen <stephen@puppetlabs.com> | 2012-08-14 13:38:08 +0100 |
---|---|---|
committer | Stephen <stephen@puppetlabs.com> | 2012-08-14 13:38:08 +0100 |
commit | d2c1e07e8088fb2372d258cfdd27ee4aab10cef1 (patch) | |
tree | 40669ccca813971fa813de7720176e12c24e2392 /lib/puppet | |
parent | e2954b26c191055fb084162a31d63058677d3026 (diff) | |
download | puppet-inifile-d2c1e07e8088fb2372d258cfdd27ee4aab10cef1.tar.gz puppet-inifile-d2c1e07e8088fb2372d258cfdd27ee4aab10cef1.tar.bz2 |
Fixed regex to match sections and settings with non alphanumeric
characters. Fixed writing to file without any sections at all.
Fixed exists checking for variable type by always casting to string
and added all the tests for the above items.
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/provider/ini_setting/ruby.rb | 2 | ||||
-rw-r--r-- | lib/puppet/util/ini_file.rb | 11 |
2 files changed, 6 insertions, 7 deletions
diff --git a/lib/puppet/provider/ini_setting/ruby.rb b/lib/puppet/provider/ini_setting/ruby.rb index f04af06..9f13dff 100644 --- a/lib/puppet/provider/ini_setting/ruby.rb +++ b/lib/puppet/provider/ini_setting/ruby.rb @@ -2,7 +2,7 @@ require File.expand_path('../../../util/ini_file', __FILE__) Puppet::Type.type(:ini_setting).provide(:ruby) do def exists? - ini_file.get_value(resource[:section], resource[:setting]) == resource[:value] + ini_file.get_value(resource[:section], resource[:setting]) == resource[:value].to_s end def create diff --git a/lib/puppet/util/ini_file.rb b/lib/puppet/util/ini_file.rb index 51dfda7..0505462 100644 --- a/lib/puppet/util/ini_file.rb +++ b/lib/puppet/util/ini_file.rb @@ -5,14 +5,13 @@ module Puppet module Util class IniFile - SECTION_REGEX = /^\s*\[([\w\d\.]+)\]\s*$/ - SETTING_REGEX = /^\s*([\w\d\.]+)\s*=\s*([\w\d\.]+)\s*$/ + SECTION_REGEX = /^\s*\[([\S.]+)\]\s*$/ + SETTING_REGEX = /^\s*([\S]+)\s*=\s*([\S]+)\s*$/ def initialize(path) @path = path @section_names = [] @sections_hash = {} - parse_file end @@ -43,7 +42,8 @@ module Util def save File.open(@path, 'w') do |fh| first_section = @sections_hash[@section_names[0]] - (0..first_section.start_line - 1).each do |line_num| + first_section.start_line == nil ? start_line = 0 : start_line = first_section.start_line + (0..start_line - 1).each do |line_num| fh.puts(lines[line_num]) end @@ -93,7 +93,6 @@ module Util elsif (match = SETTING_REGEX.match(line)) settings[match[1]] = match[2] end - line_iter.next end end @@ -129,4 +128,4 @@ module Util end end -end +end
\ No newline at end of file |