diff options
author | Luke Kanies <luke@madstop.com> | 2008-08-24 20:54:47 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-08-26 22:40:41 -0700 |
commit | 30dea6839b0360e2fabbeb833e6c2b8658d3f53c (patch) | |
tree | 0be9491fa9a5aee7137925731f6e9df6269941ca | |
parent | 40e76fb83ef466425fec736abbf1913a6426bf01 (diff) | |
download | puppet-30dea6839b0360e2fabbeb833e6c2b8658d3f53c.tar.gz puppet-30dea6839b0360e2fabbeb833e6c2b8658d3f53c.tar.xz puppet-30dea6839b0360e2fabbeb833e6c2b8658d3f53c.zip |
Adding a 'plural?' method to the Indirection::Request class.
I'm in the process of creating a new service for handling
all of the http calls, including generation of the RESTian
URL. This service obviously needs to know whether the url should
be plural or singular, and the request knows the method in use,
so it can easily answer the question.
Signed-off-by: Luke Kanies <luke@madstop.com>
-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 |