summaryrefslogtreecommitdiff
path: root/lib/rubygems/source
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/source')
-rw-r--r--lib/rubygems/source/git.rb41
-rw-r--r--lib/rubygems/source/installed.rb5
-rw-r--r--lib/rubygems/source/local.rb41
-rw-r--r--lib/rubygems/source/lock.rb1
-rw-r--r--lib/rubygems/source/specific_file.rb10
-rw-r--r--lib/rubygems/source/vendor.rb1
6 files changed, 60 insertions, 39 deletions
diff --git a/lib/rubygems/source/git.rb b/lib/rubygems/source/git.rb
index 70e8d1b06e..baf2f9dd4c 100644
--- a/lib/rubygems/source/git.rb
+++ b/lib/rubygems/source/git.rb
@@ -58,7 +58,6 @@ class Gem::Source::Git < Gem::Source
@remote = true
@root_dir = Gem.dir
- @git = ENV["git"] || "git"
end
def <=>(other)
@@ -81,6 +80,10 @@ class Gem::Source::Git < Gem::Source
@need_submodules == other.need_submodules
end
+ def git_command
+ ENV.fetch("git", "git")
+ end
+
##
# Checks out the files for the repository into the install_dir.
@@ -90,18 +93,18 @@ class Gem::Source::Git < Gem::Source
return false unless File.exist? repo_cache_dir
unless File.exist? install_dir
- system @git, "clone", "--quiet", "--no-checkout",
+ system git_command, "clone", "--quiet", "--no-checkout",
repo_cache_dir, install_dir
end
Dir.chdir install_dir do
- system @git, "fetch", "--quiet", "--force", "--tags", install_dir
+ system git_command, "fetch", "--quiet", "--force", "--tags", install_dir
- success = system @git, "reset", "--quiet", "--hard", rev_parse
+ success = system git_command, "reset", "--quiet", "--hard", rev_parse
if @need_submodules
require "open3"
- _, status = Open3.capture2e(@git, "submodule", "update", "--quiet", "--init", "--recursive")
+ _, status = Open3.capture2e(git_command, "submodule", "update", "--quiet", "--init", "--recursive")
success &&= status.success?
end
@@ -118,11 +121,11 @@ class Gem::Source::Git < Gem::Source
if File.exist? repo_cache_dir
Dir.chdir repo_cache_dir do
- system @git, "fetch", "--quiet", "--force", "--tags",
+ system git_command, "fetch", "--quiet", "--force", "--tags",
@repository, "refs/heads/*:refs/heads/*"
end
else
- system @git, "clone", "--quiet", "--bare", "--no-hardlinks",
+ system git_command, "clone", "--quiet", "--bare", "--no-hardlinks",
@repository, repo_cache_dir
end
end
@@ -157,12 +160,14 @@ class Gem::Source::Git < Gem::Source
end
def pretty_print(q) # :nodoc:
- q.group 2, "[Git: ", "]" do
- q.breakable
- q.text @repository
+ q.object_group(self) do
+ q.group 2, "[Git: ", "]" do
+ q.breakable
+ q.text @repository
- q.breakable
- q.text @reference
+ q.breakable
+ q.text @reference
+ end
end
end
@@ -180,7 +185,7 @@ class Gem::Source::Git < Gem::Source
hash = nil
Dir.chdir repo_cache_dir do
- hash = Gem::Util.popen(@git, "rev-parse", @reference).strip
+ hash = Gem::Util.popen(git_command, "rev-parse", @reference).strip
end
raise Gem::Exception,
@@ -199,7 +204,7 @@ class Gem::Source::Git < Gem::Source
return [] unless install_dir
Dir.chdir install_dir do
- Dir["{,*,*/*}.gemspec"].map do |spec_file|
+ Dir["{,*,*/*}.gemspec"].filter_map do |spec_file|
directory = File.dirname spec_file
file = File.basename spec_file
@@ -216,19 +221,19 @@ class Gem::Source::Git < Gem::Source
end
spec
end
- end.compact
+ end
end
end
##
- # A hash for the git gem based on the git repository URI.
+ # A hash for the git gem based on the git repository Gem::URI.
def uri_hash # :nodoc:
require_relative "../openssl"
normalized =
- if @repository =~ %r{^\w+://(\w+@)?}
- uri = URI(@repository).normalize.to_s.sub %r{/$},""
+ if @repository.match?(%r{^\w+://(\w+@)?})
+ uri = Gem::URI(@repository).normalize.to_s.sub %r{/$},""
uri.sub(/\A(\w+)/) { $1.downcase }
else
@repository
diff --git a/lib/rubygems/source/installed.rb b/lib/rubygems/source/installed.rb
index afb6674b88..f5c96fee51 100644
--- a/lib/rubygems/source/installed.rb
+++ b/lib/rubygems/source/installed.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
##
# Represents an installed gem. This is used for dependency resolution.
@@ -31,6 +32,8 @@ class Gem::Source::Installed < Gem::Source
end
def pretty_print(q) # :nodoc:
- q.text "[Installed]"
+ q.object_group(self) do
+ q.text "[Installed]"
+ end
end
end
diff --git a/lib/rubygems/source/local.rb b/lib/rubygems/source/local.rb
index e8553a4289..4bef31a265 100644
--- a/lib/rubygems/source/local.rb
+++ b/lib/rubygems/source/local.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
##
# The local source finds gems in the current directory for fulfilling
# dependencies.
@@ -28,7 +29,7 @@ class Gem::Source::Local < Gem::Source
def inspect # :nodoc:
keys = @specs ? @specs.keys.sort : "NOT LOADED"
- "#<%s specs: %p>" % [self.class, keys]
+ format("#<%s specs: %p>", self.class, keys)
end
def load_specs(type) # :nodoc:
@@ -39,10 +40,11 @@ class Gem::Source::Local < Gem::Source
Dir["*.gem"].each do |file|
pkg = Gem::Package.new(file)
+ spec = pkg.spec
rescue SystemCallError, Gem::Package::FormatError
# ignore
else
- tup = pkg.spec.name_tuple
+ tup = spec.name_tuple
@specs[tup] = [File.expand_path(file), pkg]
case type
@@ -74,25 +76,28 @@ class Gem::Source::Local < Gem::Source
end
def find_gem(gem_name, version = Gem::Requirement.default, prerelease = false) # :nodoc:
+ find_all_gems(gem_name, version, prerelease).max_by(&:version)
+ end
+
+ def find_all_gems(gem_name, version = Gem::Requirement.default, prerelease = false) # :nodoc:
load_specs :complete
found = []
@specs.each do |n, data|
- if n.name == gem_name
- s = data[1].spec
-
- if version.satisfied_by?(s.version)
- if prerelease
- found << s
- elsif !s.version.prerelease? || version.prerelease?
- found << s
- end
+ next unless n.name == gem_name
+ s = data[1].spec
+
+ if version.satisfied_by?(s.version)
+ if prerelease
+ found << s
+ elsif !s.version.prerelease? || version.prerelease?
+ found << s
end
end
end
- found.max_by {|s| s.version }
+ found
end
def fetch_spec(name) # :nodoc:
@@ -116,10 +121,14 @@ class Gem::Source::Local < Gem::Source
end
def pretty_print(q) # :nodoc:
- q.group 2, "[Local gems:", "]" do
- q.breakable
- q.seplist @specs.keys do |v|
- q.text v.full_name
+ q.object_group(self) do
+ q.group 2, "[Local gems:", "]" do
+ q.breakable
+ if @specs
+ q.seplist @specs.keys do |v|
+ q.text v.full_name
+ end
+ end
end
end
end
diff --git a/lib/rubygems/source/lock.rb b/lib/rubygems/source/lock.rb
index c37230388e..70849210bd 100644
--- a/lib/rubygems/source/lock.rb
+++ b/lib/rubygems/source/lock.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
##
# A Lock source wraps an installed gem's source and sorts before other sources
# during dependency resolution. This allows RubyGems to prefer gems from
diff --git a/lib/rubygems/source/specific_file.rb b/lib/rubygems/source/specific_file.rb
index 552aeba50f..dde1d48a21 100644
--- a/lib/rubygems/source/specific_file.rb
+++ b/lib/rubygems/source/specific_file.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
##
# A source representing a single .gem file. This is used for installation of
# local gems.
@@ -33,7 +34,6 @@ class Gem::Source::SpecificFile < Gem::Source
def fetch_spec(name) # :nodoc:
return @spec if name == @name
raise Gem::Exception, "Unable to find '#{name}'"
- @spec
end
def download(spec, dir = nil) # :nodoc:
@@ -42,9 +42,11 @@ class Gem::Source::SpecificFile < Gem::Source
end
def pretty_print(q) # :nodoc:
- q.group 2, "[SpecificFile:", "]" do
- q.breakable
- q.text @path
+ q.object_group(self) do
+ q.group 2, "[SpecificFile:", "]" do
+ q.breakable
+ q.text @path
+ end
end
end
diff --git a/lib/rubygems/source/vendor.rb b/lib/rubygems/source/vendor.rb
index f25ac13eef..44ef614441 100644
--- a/lib/rubygems/source/vendor.rb
+++ b/lib/rubygems/source/vendor.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
##
# This represents a vendored source that is similar to an installed gem.