Return the full path to the cached gem file matching the given name and
version requirement. Returns ‘nil’ if no match.
Example:
get_path'rake','> 0.4'# "/usr/lib/ruby/gems/1.8/cache/rake-0.4.2.gem"get_path'rake','< 0.1'# nilget_path'rak'# nil (exact name required)
# File lib/rubygems/commands/unpack_command.rb, line 112
def get_path dependency
return dependency.name if dependency.name =~ /\.gem$/
specs = dependency.matching_specs
selected = specs.sort_by { |s| s.version }.last # HACK: hunt last down
return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless
selected
return unless dependency.name =~ /^#{selected.name}$/
# We expect to find (basename).gem in the 'cache' directory. Furthermore,
# the name match must be exact (ignoring case).
path = find_in_cache File.basename selected.cache_file
return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless path
path
end