diff options
-rw-r--r-- | lib/puppet/indirector/request.rb | 10 | ||||
-rwxr-xr-x | spec/unit/indirector/request.rb | 12 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb index 194b9e031..49cc01aab 100644 --- a/lib/puppet/indirector/request.rb +++ b/lib/puppet/indirector/request.rb @@ -1,7 +1,8 @@ require 'puppet/indirector' -# Provide any attributes or functionality needed for indirected -# instances. +# This class encapsulates all of the information you need to make an +# Indirection call, and as a a result also handles REST calls. It's somewhat +# analogous to an HTTP Request object, except tuned for our Indirector. class Puppet::Indirector::Request attr_accessor :indirection_name, :key, :method, :options, :instance, :node, :ip, :authenticated @@ -50,6 +51,11 @@ class Puppet::Indirector::Request Puppet::Indirector::Indirection.instance(@indirection_name) end + # Are we trying to interact with multiple resources, or just one? + def plural? + method == :search + end + private # Parse the key as a URI, setting attributes appropriately. diff --git a/spec/unit/indirector/request.rb b/spec/unit/indirector/request.rb index 6169a09b4..18f625946 100755 --- a/spec/unit/indirector/request.rb +++ b/spec/unit/indirector/request.rb @@ -135,4 +135,16 @@ describe Puppet::Indirector::Request do request.indirection.should equal(ind) end + + it "should have a method for determining if the request is plural or singular" do + Puppet::Indirector::Request.new(:myind, :method, :key).should respond_to(:plural?) + end + + it "should be considered plural if the method is 'search'" do + Puppet::Indirector::Request.new(:myind, :search, :key).should be_plural + end + + it "should not be considered plural if the method is not 'search'" do + Puppet::Indirector::Request.new(:myind, :find, :key).should_not be_plural + end end |