diff options
author | Luke Kanies <luke@madstop.com> | 2008-10-06 19:03:40 -0500 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-10-08 10:56:09 +1100 |
commit | 765db307f875a52b7dec386b0af90f8e5b4590bb (patch) | |
tree | 52d245b9521003bc3548059f23aed8e5cb2a565d /lib/puppet/util | |
parent | fb14e91226e494210c3b6c88d8553a745e4ac3ed (diff) | |
download | puppet-765db307f875a52b7dec386b0af90f8e5b4590bb.tar.gz puppet-765db307f875a52b7dec386b0af90f8e5b4590bb.tar.xz puppet-765db307f875a52b7dec386b0af90f8e5b4590bb.zip |
Adding partial spec tests for Puppet::Util::Metric.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet/util')
-rw-r--r-- | lib/puppet/util/metric.rb | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/puppet/util/metric.rb b/lib/puppet/util/metric.rb index ca23aa87f..722277e33 100644 --- a/lib/puppet/util/metric.rb +++ b/lib/puppet/util/metric.rb @@ -5,6 +5,8 @@ require 'puppet' class Puppet::Util::Metric # Load the library as a feature, so we can test its presence. + # It's only used by this class, so there's no reason to move it + # to the main feature list. Puppet.features.add :rrd, :libs => 'RRDtool' attr_accessor :type, :name, :value, :label @@ -93,11 +95,7 @@ class Puppet::Util::Metric def initialize(name,label = nil) @name = name.to_s - if label - @label = label - else - @label = name.to_s.capitalize.gsub("_", " ") - end + @label = label || labelize(name) @values = [] end @@ -107,9 +105,7 @@ class Puppet::Util::Metric end def newvalue(name,value,label = nil) - unless label - label = name.to_s.capitalize.gsub("_", " ") - end + label ||= labelize(name) @values.push [name,label,value] end @@ -145,7 +141,16 @@ class Puppet::Util::Metric def values @values.sort { |a, b| a[1] <=> b[1] } end + + private + + # Convert a name into a label. + def labelize(name) + name.to_s.capitalize.gsub("_", " ") + end end +# This is necessary because we changed the class path in early 2007, +# and reports directly yaml-dump these metrics, so both client and server +# have to agree on the class name. Puppet::Metric = Puppet::Util::Metric - |