diff options
author | Steven Danna <steve@opscode.com> | 2014-04-09 00:03:57 -0700 |
---|---|---|
committer | Bryan McLellan <btm@getchef.com> | 2014-05-02 12:19:40 -0700 |
commit | 0179565678a8f75e1c5c7151fae2b141ef74f76d (patch) | |
tree | 54179b61cabf06bc2686b6bb04600f35f810b268 /lib | |
parent | aa2b95e5515ad6d4855d0de6c72604f5d0ae04d0 (diff) | |
download | chef-0179565678a8f75e1c5c7151fae2b141ef74f76d.tar.gz |
[CHEF-5162] Move argument parsing for source to new method
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/resource/remote_file.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb index a10a0996a6..6334b1bf44 100644 --- a/lib/chef/resource/remote_file.rb +++ b/lib/chef/resource/remote_file.rb @@ -40,16 +40,16 @@ class Chef @provider = Chef::Provider::RemoteFile end + # source can take any of the following as arguments + # - A single string argument + # - Multiple string arguments + # - An array or strings + # - A delayed evaluator that evaluates to a string + # or array of strings + # All strings must be parsable as URIs. + # source returns an array of strings. def source(*args) - arg = if args.empty? - nil - elsif args[0].is_a?(Chef::DelayedEvaluator) && args.count == 1 - args[0] - elsif args.any? {|a| a.is_a?(Chef::DelayedEvaluator)} && args.count > 1 - raise Exceptions::InvalidRemoteFileURI, "Only 1 DelayedEvaluator is allowed" - else - Array(args).flatten - end + arg = parse_source_args(args) ret = set_or_return(:source, arg, { :callbacks => { @@ -62,6 +62,18 @@ class Chef end end + def parse_source_args(args) + if args.empty? + nil + elsif args[0].is_a?(Chef::DelayedEvaluator) && args.count == 1 + args[0] + elsif args.any? {|a| a.is_a?(Chef::DelayedEvaluator)} && args.count > 1 + raise Exceptions::InvalidRemoteFileURI, "Only 1 source argument allowed when using a lazy evaluator" + else + Array(args).flatten + end + end + def checksum(args=nil) set_or_return( :checksum, |