summaryrefslogtreecommitdiffstats
path: root/lib/puppet/indirector/request.rb
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-03-29 17:10:40 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit23ccefe0e8b51af19a0283c0d8eb3de09b6e4c31 (patch)
treef5a13141985b8956987b0aad3f84269be7902243 /lib/puppet/indirector/request.rb
parentd8e1b272ec321d5f86558672252de60983751a15 (diff)
downloadpuppet-23ccefe0e8b51af19a0283c0d8eb3de09b6e4c31.tar.gz
puppet-23ccefe0e8b51af19a0283c0d8eb3de09b6e4c31.tar.xz
puppet-23ccefe0e8b51af19a0283c0d8eb3de09b6e4c31.zip
REST: hide Request object
This change to the REST branch restores some sanity by explicitly allowing a destination URL for indirector save() calls, removing a hack that I was using to accomplish this.
Diffstat (limited to 'lib/puppet/indirector/request.rb')
-rw-r--r--lib/puppet/indirector/request.rb24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb
index 14608d0dc..cd354ac16 100644
--- a/lib/puppet/indirector/request.rb
+++ b/lib/puppet/indirector/request.rb
@@ -52,9 +52,14 @@ class Puppet::Indirector::Request
ignore_terminus
end
- def initialize(indirection_name, method, key, options = {})
- options ||= {}
- raise ArgumentError, "Request options must be a hash, not %s" % options.class unless options.is_a?(Hash)
+ def initialize(indirection_name, method, key_or_instance, options_or_instance = {})
+ if options_or_instance.is_a? Hash
+ options = options_or_instance
+ @instance = nil
+ else
+ options = {}
+ @instance = options_or_instance
+ end
self.indirection_name = indirection_name
self.method = method
@@ -63,7 +68,13 @@ class Puppet::Indirector::Request
@options = options.inject({}) { |hash, ary| hash[ary[0].to_sym] = ary[1]; hash }
- if key.is_a?(String) or key.is_a?(Symbol)
+ if key_or_instance.is_a?(String) || key_or_instance.is_a?(Symbol)
+ key = key_or_instance
+ else
+ @instance = key_or_instance if ! @instance
+ end
+
+ if key
# If the request key is a URI, then we need to treat it specially,
# because it rewrites the key. We could otherwise strip server/port/etc
# info out in the REST class, but it seemed bad design for the REST
@@ -73,10 +84,9 @@ class Puppet::Indirector::Request
else
@key = key
end
- else
- @instance = key
- @key = @instance.name
end
+
+ @key = @instance.name if ! @key and @instance
end
# Look up the indirection based on the name provided.