summaryrefslogtreecommitdiff
path: root/lib/chef/provider
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-04-04 09:50:31 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2017-04-04 12:50:43 -0700
commit467499fbbbd3a29bdee2b171655f0d5f441e531e (patch)
tree8fda465d4bdf71fe26c781ba77a0f5fa0d06ca19 /lib/chef/provider
parent6b8ca8c387b01799ed94fcd8555ba30618905a1d (diff)
downloadchef-467499fbbbd3a29bdee2b171655f0d5f441e531e.tar.gz
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 <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/provider')
-rw-r--r--lib/chef/provider/package/rubygems.rb17
1 files changed, 10 insertions, 7 deletions
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