Procházet zdrojové kódy

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 před 11 roky
rodič
revize
6b19864
1 změnil soubory, kde provedl 9 přidání a 9 odebrání
  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
 module Util
   class IniFile
   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 = ' = ')
     def initialize(path, key_val_separator = ' = ')
       @path = path
       @path = path
@@ -172,7 +172,7 @@ module Util
       line, line_num = line_iter.next
       line, line_num = line_iter.next
 
 
       while line
       while line
-        if (match = SECTION_REGEX.match(line))
+        if (match = @@SECTION_REGEX.match(line))
           section = read_section(match[1], line_num, line_iter)
           section = read_section(match[1], line_num, line_iter)
           add_section(section)
           add_section(section)
         end
         end
@@ -186,9 +186,9 @@ module Util
       min_indentation = nil
       min_indentation = nil
       while true
       while true
         line, line_num = line_iter.peek
         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)
           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]
           settings[match[2]] = match[4]
           indentation = match[1].length
           indentation = match[1].length
           min_indentation = [indentation, min_indentation || indentation].min
           min_indentation = [indentation, min_indentation || indentation].min
@@ -200,7 +200,7 @@ module Util
 
 
     def update_line(section, setting, value)
     def update_line(section, setting, value)
       (section.start_line..section.end_line).each do |line_num|
       (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)
           if (match[2] == setting)
             lines[line_num] = "#{match[1]}#{match[2]}#{match[3]}#{value}"
             lines[line_num] = "#{match[1]}#{match[2]}#{match[3]}#{value}"
           end
           end
@@ -210,7 +210,7 @@ module Util
 
 
     def remove_line(section, setting)
     def remove_line(section, setting)
       (section.start_line..section.end_line).each do |line_num|
       (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)
           if (match[2] == setting)
             lines.delete_at(line_num)
             lines.delete_at(line_num)
           end
           end
@@ -249,7 +249,7 @@ module Util
     def find_commented_setting(section, setting)
     def find_commented_setting(section, setting)
       return nil if section.is_new_section?
       return nil if section.is_new_section?
       (section.start_line..section.end_line).each do |line_num|
       (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)
           if (match[3] == setting)
             return { :match => match, :line_num => line_num }
             return { :match => match, :line_num => line_num }
           end
           end