summaryrefslogtreecommitdiff
path: root/lib/chef/provider/package/rubygems.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-02-24 13:28:16 -0800
committerdanielsdeleo <dan@opscode.com>2013-02-27 11:12:15 -0800
commitb217dc3f2a80866d484a6cad33190dd321b3e2b7 (patch)
tree9565dce2135c96b882b0668c9a3c3fbb66a6802a /lib/chef/provider/package/rubygems.rb
parent06322ffb233dc608cc14b8b50e45a13cbddee17b (diff)
downloadchef-b217dc3f2a80866d484a6cad33190dd321b3e2b7.tar.gz
[CHEF-3933] support new gem dependency installer return type
in rubygems commit 432fc4818bbf14dfa5e49bbc1950eaa6d3fde133, return type of dependency_installer's #find_gems_with_sources is changed to return a Gem::AvailableSet collection instead of an ordered Array.
Diffstat (limited to 'lib/chef/provider/package/rubygems.rb')
-rw-r--r--lib/chef/provider/package/rubygems.rb21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb
index 2a778fdb14..5b47532597 100644
--- a/lib/chef/provider/package/rubygems.rb
+++ b/lib/chef/provider/package/rubygems.rb
@@ -165,14 +165,23 @@ class Chef
# Find the newest gem version available from Gem.sources that satisfies
# the constraints of +gem_dependency+
def find_newest_remote_version(gem_dependency, *sources)
- # DependencyInstaller sorts the results such that the last one is
- # always the one it considers best.
- spec_with_source = dependency_installer.find_gems_with_sources(gem_dependency).last
+ available_gems = dependency_installer.find_gems_with_sources(gem_dependency)
+ spec, source = if available_gems.respond_to?(:last)
+ # DependencyInstaller sorts the results such that the last one is
+ # always the one it considers best.
+ spec_with_source = available_gems.last
+ spec_with_source && spec_with_source
+ else
+ # Rubygems 2.0 returns a Gem::Available set, which is a
+ # collection of AvailableSet::Tuple structs
+ available_gems.pick_best!
+ best_gem = available_gems.set.first
+ best_gem && [best_gem.spec, best_gem.source]
+ end
- spec = spec_with_source && spec_with_source[0]
- version = spec && spec_with_source[0].version
+ version = spec && spec.version
if version
- logger.debug { "#{@new_resource} found gem #{spec.name} version #{version} for platform #{spec.platform} from #{spec_with_source[1]}" }
+ logger.debug { "#{@new_resource} found gem #{spec.name} version #{version} for platform #{spec.platform} from #{source}" }
version
else
source_list = sources.compact.empty? ? "[#{Gem.sources.to_a.join(', ')}]" : "[#{sources.join(', ')}]"