diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:08 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:08 -0700 |
| commit | eefccf252527dc5b69af5959b0b0e2ddb5c91b74 (patch) | |
| tree | a37e13c9cd4aab7e8671004cf4f83000b52c96a8 /lib/puppet/external | |
| parent | 184132e07fc1461555cb4da842df15f32842a843 (diff) | |
| download | puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.tar.gz puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.tar.xz puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.zip | |
Code smell: English names for special globals rather than line-noise
* Replaced 36 occurances of [$][?] with $CHILD_STATUS
3 Examples:
The code:
print "%s finished with exit code %s\n" % [host, $?.exitstatus]
becomes:
print "%s finished with exit code %s\n" % [host, $CHILD_STATUS.exitstatus]
The code:
$stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus]
becomes:
$stderr.puts "Could not find host for PID %s with status %s" % [pid, $CHILD_STATUS.exitstatus]
The code:
unless $? == 0
becomes:
unless $CHILD_STATUS == 0
* Replaced 3 occurances of [$][$] with $PID
3 Examples:
The code:
Process.kill(:HUP, $$) if restart_requested?
becomes:
Process.kill(:HUP, $PID) if restart_requested?
The code:
if pid == $$
becomes:
if pid == $PID
The code:
host[:name] = "!invalid.hostname.$$$"
becomes:
host[:name] = "!invalid.hostname.$PID$"
* Replaced 7 occurances of [$]& with $MATCH
3 Examples:
The code:
work.slice!(0, $&.length)
becomes:
work.slice!(0, $MATCH.length)
The code:
if $&
becomes:
if $MATCH
The code:
if $&
becomes:
if $MATCH
* Replaced 28 occurances of [$]:(?!:) with $LOAD_PATH
3 Examples:
The code:
sitelibdir = $:.find { |x| x =~ /site_ruby/ }
becomes:
sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ }
The code:
$:.unshift "lib"
becomes:
$LOAD_PATH.unshift "lib"
The code:
$:.shift
becomes:
$LOAD_PATH.shift
* Replaced 3 occurances of [$]! with $ERROR_INFO
3 Examples:
The code:
$LOG.fatal("Problem reading #{filepath}: #{$!}")
becomes:
$LOG.fatal("Problem reading #{filepath}: #{$ERROR_INFO}")
The code:
$stderr.puts "Couldn't build man pages: " + $!
becomes:
$stderr.puts "Couldn't build man pages: " + $ERROR_INFO
The code:
$stderr.puts $!.message
becomes:
$stderr.puts $ERROR_INFO.message
* Replaced 3 occurances of ^(.*)[$]" with \1$LOADED_FEATURES
3 Examples:
The code:
unless $".index 'racc/parser.rb'
becomes:
unless $LOADED_FEATURES.index 'racc/parser.rb'
The code:
$".push 'racc/parser.rb'
becomes:
$LOADED_FEATURES.push 'racc/parser.rb'
The code:
$".should be_include("tmp/myfile.rb")
becomes:
$LOADED_FEATURES.should be_include("tmp/myfile.rb")
Diffstat (limited to 'lib/puppet/external')
| -rw-r--r-- | lib/puppet/external/nagios/parser.rb | 10 | ||||
| -rw-r--r-- | lib/puppet/external/pson/pure/generator.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/external/pson/pure/parser.rb | 2 |
3 files changed, 8 insertions, 8 deletions
diff --git a/lib/puppet/external/nagios/parser.rb b/lib/puppet/external/nagios/parser.rb index deea9f3bc..4a1f4c98d 100644 --- a/lib/puppet/external/nagios/parser.rb +++ b/lib/puppet/external/nagios/parser.rb @@ -7,8 +7,8 @@ # parser.rb: generated by racc (runtime embedded) # ###### racc/parser.rb begin -unless $".index 'racc/parser.rb' -$".push 'racc/parser.rb' +unless $LOADED_FEATURES.index 'racc/parser.rb' +$LOADED_FEATURES.push 'racc/parser.rb' self.class.module_eval <<'..end racc/parser.rb modeval..id5256434e8a', 'racc/parser.rb', 1 # @@ -482,7 +482,7 @@ end # The lexer. Very simple. def token @src.sub!(/\A\n/,'') - if $& + if $MATCH @line += 1 return [ :RETURN, "\n" ] end @@ -495,12 +495,12 @@ def token # remove comments from this line @src.sub!(/\A[ \t]*;.*\n/,"\n") - if $& + if $MATCH return [:INLINECOMMENT, ""] end @src.sub!(/\A#.*\n/,"\n") - if $& + if $MATCH return [:COMMENT, ""] end diff --git a/lib/puppet/external/pson/pure/generator.rb b/lib/puppet/external/pson/pure/generator.rb index 6656ed1b2..42981b9dc 100644 --- a/lib/puppet/external/pson/pure/generator.rb +++ b/lib/puppet/external/pson/pure/generator.rb @@ -43,7 +43,7 @@ module PSON string = string.dup string << '' # XXX workaround: avoid buffer sharing string.force_encoding(Encoding::ASCII_8BIT) - string.gsub!(/["\\\x0-\x1f]/) { MAP[$&] } + string.gsub!(/["\\\x0-\x1f]/) { MAP[$MATCH] } string.gsub!(/( (?: [\xc2-\xdf][\x80-\xbf] | @@ -63,7 +63,7 @@ module PSON end else def utf8_to_pson(string) # :nodoc: - string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } + string = string.gsub(/["\\\x0-\x1f]/) { MAP[$MATCH] } string.gsub!(/( (?: [\xc2-\xdf][\x80-\xbf] | diff --git a/lib/puppet/external/pson/pure/parser.rb b/lib/puppet/external/pson/pure/parser.rb index ef14d4009..ef05637e4 100644 --- a/lib/puppet/external/pson/pure/parser.rb +++ b/lib/puppet/external/pson/pure/parser.rb @@ -132,7 +132,7 @@ module PSON if scan(STRING) return '' if self[1].empty? string = self[1].gsub(%r{(?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff])}n) do |c| - if u = UNESCAPE_MAP[$&[1]] + if u = UNESCAPE_MAP[$MATCH[1]] u else # \uXXXX bytes = '' |
