diff options
author | Steven Danna <steve@opscode.com> | 2014-04-06 15:05:28 -0700 |
---|---|---|
committer | Bryan McLellan <btm@getchef.com> | 2014-05-02 12:19:40 -0700 |
commit | aa2b95e5515ad6d4855d0de6c72604f5d0ae04d0 (patch) | |
tree | d03e0ed38850f1e63977fb2b98150fcc26741714 /lib/chef/resource/remote_file.rb | |
parent | 28f30348abf715c4d41ef3def5218c7e42d299ba (diff) | |
download | chef-aa2b95e5515ad6d4855d0de6c72604f5d0ae04d0.tar.gz |
[CHEF-5162] Support DelayedEvaluator for remote_file's source attribute
This commit adds the ability to pass a single DelayedEvaluator to the
source attribute of the remote_file resource. If more than one
DelayedEvalutor is passed, an error will be raised.
The source attribute now accepts:
- A single string argument,
- Multiple string arguments
- A single array argument
- A single delayed evaluator argument
Technically, it also accepts
- An array of arrays
but this case is not tested.
Diffstat (limited to 'lib/chef/resource/remote_file.rb')
-rw-r--r-- | lib/chef/resource/remote_file.rb | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb index 24d2562a9b..a10a0996a6 100644 --- a/lib/chef/resource/remote_file.rb +++ b/lib/chef/resource/remote_file.rb @@ -41,12 +41,24 @@ class Chef end def source(*args) - if not args.empty? - args = Array(args).flatten - validate_source(args) - @source = args - elsif self.instance_variable_defined?(:@source) == true - @source + 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 + ret = set_or_return(:source, + arg, + { :callbacks => { + :validate_source => method(:validate_source) + }}) + if ret.is_a? String + Array(ret) + else + ret end end @@ -107,6 +119,7 @@ class Chef private def validate_source(source) + source = Array(source).flatten raise ArgumentError, "#{resource_name} has an empty source" if source.empty? source.each do |src| unless absolute_uri?(src) @@ -114,6 +127,7 @@ class Chef "#{src.inspect} is not a valid `source` parameter for #{resource_name}. `source` must be an absolute URI or an array of URIs." end end + true end def absolute_uri?(source) |