summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/util/metric.rb9
-rwxr-xr-xspec/unit/util/metric.rb9
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/puppet/util/metric.rb b/lib/puppet/util/metric.rb
index 722277e33..e6d7678aa 100644
--- a/lib/puppet/util/metric.rb
+++ b/lib/puppet/util/metric.rb
@@ -14,6 +14,15 @@ class Puppet::Util::Metric
attr_writer :basedir
+ # Return a specific value
+ def [](name)
+ if value = @values.find { |v| v[0] == name }
+ return value[2]
+ else
+ return nil
+ end
+ end
+
def basedir
if defined? @basedir
@basedir
diff --git a/spec/unit/util/metric.rb b/spec/unit/util/metric.rb
index 7aa04486c..3501aac90 100755
--- a/spec/unit/util/metric.rb
+++ b/spec/unit/util/metric.rb
@@ -75,6 +75,15 @@ describe Puppet::Util::Metric do
@metric.values.should == [[:bar, "a", 10], [:foo, "b", 10]]
end
+ it "should use an array indexer method to retrieve individual values" do
+ @metric.newvalue(:foo, 10)
+ @metric[:foo].should == 10
+ end
+
+ it "should return nil if the named value cannot be found" do
+ @metric[:foo].should be_nil
+ end
+
# LAK: I'm not taking the time to develop these tests right now.
# I expect they should actually be extracted into a separate class
# anyway.