summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-10-06 19:06:21 -0500
committerJames Turnbull <james@lovedthanlost.net>2008-10-08 10:56:10 +1100
commit0b1e60f69a03e6525e1a9eefd748c59b4fc5261c (patch)
treeed1710bfd0b7f11d10c95196cb2a07f534782e55
parent765db307f875a52b7dec386b0af90f8e5b4590bb (diff)
downloadpuppet-0b1e60f69a03e6525e1a9eefd748c59b4fc5261c.tar.gz
puppet-0b1e60f69a03e6525e1a9eefd748c59b4fc5261c.tar.xz
puppet-0b1e60f69a03e6525e1a9eefd748c59b4fc5261c.zip
Adding an array indexer method to Puppet::Util::Metric as requested in #1633.
Signed-off-by: Luke Kanies <luke@madstop.com>
-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.