From 8bbe0cf0c6715eeba077172a153748fff88f452b Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Wed, 21 Sep 2016 13:12:28 +0100 Subject: [PATCH] Use `source` in `gemlist` When `ensure => latest`, `gemlist` is called to determine the latest available version of a gem. If the `source` parameter is a remote gem repository, this needs to be part of the `gem list` command run. Fixes #128 Signed-off-by: Alexander Fisher --- lib/puppet/provider/rvm_gem/gem.rb | 20 +++++++++++++------- spec/spec_helper.rb | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/puppet/provider/rvm_gem/gem.rb b/lib/puppet/provider/rvm_gem/gem.rb index 704c20b0..bad412dc 100644 --- a/lib/puppet/provider/rvm_gem/gem.rb +++ b/lib/puppet/provider/rvm_gem/gem.rb @@ -27,6 +27,9 @@ def gemlist(hash) command << "--local" else command << "--remote" + if resource[:source] && source_uri(resource[:source]).scheme =~ /^http/ + command << '--source' << resource[:source].to_s + end end if name = hash[:justme] @@ -76,7 +79,6 @@ def self.gemsplit(desc) end end - def install(useversion = true) command = gembinary + ['install'] command << "-v" << resource[:ensure] if (! resource[:ensure].is_a? Symbol) and useversion @@ -89,12 +91,7 @@ def install(useversion = true) end if source = resource[:source] - begin - uri = URI.parse(source) - rescue => detail - fail "Invalid source '#{uri}': #{detail}" - end - + uri = source_uri(source) case uri.scheme when nil # no URI scheme => interpret the source as a local file @@ -123,6 +120,15 @@ def install(useversion = true) self.fail "Could not install: #{output.chomp}" if output.include?("ERROR") end + def source_uri(source) + begin + uri = URI.parse(source) + rescue => detail + fail "Invalid source '#{uri}': #{detail}" + end + uri + end + def latest # This always gets the latest version available. hash = gemlist(:justme => resource[:name]) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d6f2d800..7afbdd25 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,7 +18,8 @@ :kernel => 'Linux', :osfamily => 'RedHat', :architecture => 'x86_64', - :clientcert => 'puppet.acme.com' + :clientcert => 'puppet.acme.com', + :gnupg_installed => false }.merge({}) c.before do @@ -30,4 +31,3 @@ shared_examples :compile, :compile => true do it { should compile.with_all_deps } end -