From 467499fbbbd3a29bdee2b171655f0d5f441e531e Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 4 Apr 2017 09:50:31 -0700 Subject: Chef-13: tweaks to rubygems source option for urls By default now we don't pass any --source option or set the `Chef::Config[:rubygems_url]` to anything. This is so that if there is external config for rubygems sources we will simply have rubygems pick it up and use it (the resource acts like the command line). There is also no more magic around `--clear-sources` and if you set the property it sets the flag. If the `Chef::Config[:rubygems_url]` setting is set then that becomes the default `--source` flag sent to the command. This also supports Arrays now. If the `source` option is set to a URI (it can also be set to a filesystem path for poorly-designed-API reasons) then we do not use the default values at all. This may be an API break but this much more clearly allows users to override individual resources and is more declarative. You get what you type. Signed-off-by: Lamont Granquist --- lib/chef/provider/package/rubygems.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib/chef/provider') diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb index 9bf8fb5fbc..1269b24c93 100644 --- a/lib/chef/provider/package/rubygems.rb +++ b/lib/chef/provider/package/rubygems.rb @@ -533,18 +533,21 @@ class Chef end def install_via_gem_command(name, version) - if new_resource.source =~ /\.gem$/i + src = [] + if new_resource.source.is_a?(String) && new_resource.source =~ /\.gem$/i name = new_resource.source - elsif new_resource.clear_sources - src = " --clear-sources" - src << (new_resource.source && " --source=#{new_resource.source}" || "") else - src = new_resource.source && " --source=#{new_resource.source} --source=#{Chef::Config[:rubygems_url]}" + src << "--clear-sources" if new_resource.clear_sources + srcarry = [ new_resource.source || Chef::Config[:rubygems_url] ].flatten.compact + srcarry.each do |s| + src << "--source=#{s}" + end end + src_str = src.empty? ? "" : " #{src.join(" ")}" if !version.nil? && !version.empty? - shell_out_with_timeout!("#{gem_binary_path} install #{name} -q --no-rdoc --no-ri -v \"#{version}\"#{src}#{opts}", env: nil) + shell_out_with_timeout!("#{gem_binary_path} install #{name} -q --no-rdoc --no-ri -v \"#{version}\"#{src_str}#{opts}", env: nil) else - shell_out_with_timeout!("#{gem_binary_path} install \"#{name}\" -q --no-rdoc --no-ri #{src}#{opts}", env: nil) + shell_out_with_timeout!("#{gem_binary_path} install \"#{name}\" -q --no-rdoc --no-ri #{src_str}#{opts}", env: nil) end end -- cgit v1.2.1