We were type-checking the use of Storage for no good reason.

I've removed all of that, so we can use either resources
or their Refs for caching.

Signed-off-by: Luke Kanies <[email protected]>
---
 lib/puppet/util/storage.rb |   12 ++----------
 spec/unit/util/storage.rb  |   24 +++++-------------------
 test/util/storage.rb       |   20 --------------------
 3 files changed, 7 insertions(+), 49 deletions(-)

diff --git a/lib/puppet/util/storage.rb b/lib/puppet/util/storage.rb
index 01c4111..f863887 100644
--- a/lib/puppet/util/storage.rb
+++ b/lib/puppet/util/storage.rb
@@ -22,18 +22,10 @@ class Puppet::Util::Storage
     # types like exec, but it also means that if an object changes locations
     # in the configuration it will lose its cache.
     def self.cache(object)
-        if object.is_a? Puppet::Type
-            # We used to store things by path, now we store them by ref.
-            # In oscar(0.20.0) this changed to using the ref.
-            if @@state.include?(object.path)
-                @@state[object.ref] = @@state[object.path]
-                @@state.delete(object.path)
-            end
-            name = object.ref
-        elsif object.is_a?(Symbol)
+        if object.is_a?(Symbol)
             name = object
         else
-            raise ArgumentError, "You can only cache information for Types and 
symbols"
+            name = object.to_s
         end
 
         return @@state[name] ||= {}
diff --git a/spec/unit/util/storage.rb b/spec/unit/util/storage.rb
index c786145..71d5e79 100755
--- a/spec/unit/util/storage.rb
+++ b/spec/unit/util/storage.rb
@@ -59,25 +59,11 @@ describe Puppet::Util::Storage do
         end
     end
 
-    describe "when caching invalid objects" do
-        before(:all) do
-            @bogus_objects = [ {}, [], "foo", 42, nil, 
Tempfile.new('storage_test') ]
-        end
-
-        it "should raise an ArgumentError" do
-            @bogus_objects.each do |object|
-                proc { Puppet::Util::Storage.cache(object) }.should 
raise_error()
-            end
-        end
-
-        it "should not add anything to its internal state" do
-            @bogus_objects.each do |object|
-                begin
-                    Puppet::Util::Storage.cache(object)
-                rescue
-                    Puppet::Util::Storage.state().should == {}
-                end
-            end
+    describe "when caching something other than a resource or symbol" do
+        it "should cache by converting to a string" do
+            data = Puppet::Util::Storage.cache(42)
+            data[:yay] = true
+            Puppet::Util::Storage.cache("42")[:yay].should be_true
         end
     end
 
diff --git a/test/util/storage.rb b/test/util/storage.rb
index e2c4dce..b0efff3 100755
--- a/test/util/storage.rb
+++ b/test/util/storage.rb
@@ -74,25 +74,5 @@ class TestStorage < Test::Unit::TestCase
         assert_same Hash, state.class
         assert_equal 0, state.size
     end
-
-    def test_caching
-        hash = nil
-        one = Puppet::Type.type(:exec).new :title => "/bin/echo one"
-        [one, :yayness].each do |object|
-            assert_nothing_raised do
-                hash = Puppet::Util::Storage.cache(object)
-            end
-            assert_equal({}, hash, "Did not get empty hash back for %s" % 
object)
-
-            hash[:testing] = true
-            assert_nothing_raised do
-                hash = Puppet::Util::Storage.cache(object)
-            end
-            assert_equal({:testing => true}, hash, "Did not get hash back for 
%s" % object)
-        end
-        assert_raise(ArgumentError, "was able to cache from string") do
-            Puppet::Util::Storage.cache("somethingelse")
-        end
-    end
 end
 
-- 
1.6.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to