summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-10-23 00:20:57 -0500
committerLuke Kanies <luke@madstop.com>2007-10-23 00:20:57 -0500
commit1746751ddc0e5dd5c5d32abe2ddb4d8305d739fc (patch)
tree4e5d567ce4521909277c610bd77fb07befe54e61
parent09f9c3c52e94b5cdb33f26b464f01285a5ba8c62 (diff)
downloadpuppet-1746751ddc0e5dd5c5d32abe2ddb4d8305d739fc.tar.gz
puppet-1746751ddc0e5dd5c5d32abe2ddb4d8305d739fc.tar.xz
puppet-1746751ddc0e5dd5c5d32abe2ddb4d8305d739fc.zip
Adding post- hooks for :find and :search in the indirection class.
-rw-r--r--lib/puppet/indirector/indirection.rb9
-rwxr-xr-xspec/unit/indirector/indirection.rb20
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 50a27f771..60278be98 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -124,6 +124,9 @@ class Puppet::Indirector::Indirection
Puppet.info "Caching %s %s" % [self.name, key]
cache.save(result, *args)
end
+
+ terminus(terminus_name).post_find(result) if terminus(terminus_name).respond_to?(:post_find)
+
return result
end
end
@@ -137,7 +140,11 @@ class Puppet::Indirector::Indirection
def search(*args)
check_authorization(:search, terminus_class, args)
- terminus.search(*args)
+ result = terminus.search(*args)
+
+ terminus().post_search(result) if terminus().respond_to?(:post_search)
+
+ result
end
# these become instance methods
diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb
index c8e4cc6af..8987fef8a 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -66,6 +66,16 @@ describe Puppet::Indirector::Indirection, " when looking for a model instance" d
@terminus.expects(:find).with(@name).returns(nil)
proc { @indirection.find(@name) }.should_not raise_error
end
+
+ it "should pass the instance to the :post_find hook if there is one" do
+ class << @terminus
+ def post_find
+ end
+ end
+ @terminus.expects(:post_find).with(@instance)
+ @terminus.expects(:find).with(@name).returns(@instance)
+ @indirection.find(@name)
+ end
end
describe Puppet::Indirector::Indirection, " when removing a model instance" do
@@ -84,6 +94,16 @@ describe Puppet::Indirector::Indirection, " when searching for multiple model in
@terminus.expects(:search).with(@name).returns(@instance)
@indirection.search(@name).should == @instance
end
+
+ it "should pass the instances to the :post_search hook if there is one" do
+ class << @terminus
+ def post_search
+ end
+ end
+ @terminus.expects(:post_search).with(@instance)
+ @terminus.expects(:search).with(@name).returns(@instance)
+ @indirection.search(@name)
+ end
end
describe Puppet::Indirector::Indirection, " when storing a model instance" do