Browse Source

Change constants to class variables

Because of the way that puppet's autoloader and pluginsync work,
modules on the master get loaded twice, which means that
you can't use Ruby constants at all w/o getting warning messages.

This commit changes all of the constants in `ini_file` to class
variables, which will avoid the warning messages.
Chris Price 11 years ago
parent
commit
6b19864
1 changed files with 9 additions and 9 deletions
  1. 9 9
      lib/puppet/util/ini_file.rb

+ 9 - 9
lib/puppet/util/ini_file.rb

@@ -5,9 +5,9 @@ module Puppet
 module Util
   class IniFile
 
-    SECTION_REGEX = /^\s*\[([\w\d\.\\\/\-\:]+)\]\s*$/
-    SETTING_REGEX = /^(\s*)([\w\d\.\\\/\-]+)(\s*=\s*)([\S\s]*\S)\s*$/
-    COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([\w\d\.\\\/\-]+)(\s*=\s*)([\S\s]*\S)\s*$/
+    @@SECTION_REGEX = /^\s*\[([\w\d\.\\\/\-\:]+)\]\s*$/
+    @@SETTING_REGEX = /^(\s*)([\w\d\.\\\/\-]+)(\s*=\s*)([\S\s]*\S)\s*$/
+    @@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([\w\d\.\\\/\-]+)(\s*=\s*)([\S\s]*\S)\s*$/
 
     def initialize(path, key_val_separator = ' = ')
       @path = path
@@ -172,7 +172,7 @@ module Util
       line, line_num = line_iter.next
 
       while line
-        if (match = SECTION_REGEX.match(line))
+        if (match = @@SECTION_REGEX.match(line))
           section = read_section(match[1], line_num, line_iter)
           add_section(section)
         end
@@ -186,9 +186,9 @@ module Util
       min_indentation = nil
       while true
         line, line_num = line_iter.peek
-        if (line_num.nil? or match = SECTION_REGEX.match(line))
+        if (line_num.nil? or match = @@SECTION_REGEX.match(line))
           return Section.new(name, start_line, end_line_num, settings, min_indentation)
-        elsif (match = SETTING_REGEX.match(line))
+        elsif (match = @@SETTING_REGEX.match(line))
           settings[match[2]] = match[4]
           indentation = match[1].length
           min_indentation = [indentation, min_indentation || indentation].min
@@ -200,7 +200,7 @@ module Util
 
     def update_line(section, setting, value)
       (section.start_line..section.end_line).each do |line_num|
-        if (match = SETTING_REGEX.match(lines[line_num]))
+        if (match = @@SETTING_REGEX.match(lines[line_num]))
           if (match[2] == setting)
             lines[line_num] = "#{match[1]}#{match[2]}#{match[3]}#{value}"
           end
@@ -210,7 +210,7 @@ module Util
 
     def remove_line(section, setting)
       (section.start_line..section.end_line).each do |line_num|
-        if (match = SETTING_REGEX.match(lines[line_num]))
+        if (match = @@SETTING_REGEX.match(lines[line_num]))
           if (match[2] == setting)
             lines.delete_at(line_num)
           end
@@ -249,7 +249,7 @@ module Util
     def find_commented_setting(section, setting)
       return nil if section.is_new_section?
       (section.start_line..section.end_line).each do |line_num|
-        if (match = COMMENTED_SETTING_REGEX.match(lines[line_num]))
+        if (match = @@COMMENTED_SETTING_REGEX.match(lines[line_num]))
           if (match[3] == setting)
             return { :match => match, :line_num => line_num }
           end