diff options
| -rw-r--r-- | lib/puppet/indirector/indirection.rb | 9 | ||||
| -rwxr-xr-x | spec/unit/indirector/indirection.rb | 20 |
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 |
