diff options
Diffstat (limited to 'lib/rubygems/source')
-rw-r--r-- | lib/rubygems/source/git.rb | 50 | ||||
-rw-r--r-- | lib/rubygems/source/installed.rb | 5 | ||||
-rw-r--r-- | lib/rubygems/source/local.rb | 88 | ||||
-rw-r--r-- | lib/rubygems/source/lock.rb | 5 | ||||
-rw-r--r-- | lib/rubygems/source/specific_file.rb | 4 | ||||
-rw-r--r-- | lib/rubygems/source/vendor.rb | 3 |
6 files changed, 73 insertions, 82 deletions
diff --git a/lib/rubygems/source/git.rb b/lib/rubygems/source/git.rb index 1d964eb59a..bda63c6844 100644 --- a/lib/rubygems/source/git.rb +++ b/lib/rubygems/source/git.rb @@ -53,12 +53,12 @@ class Gem::Source::Git < Gem::Source @uri = Gem::Uri.parse(repository) @name = name @repository = repository - @reference = reference + @reference = reference || "HEAD" @need_submodules = submodules @remote = true @root_dir = Gem.dir - @git = ENV['git'] || 'git' + @git = ENV["git"] || "git" end def <=>(other) @@ -70,16 +70,14 @@ class Gem::Source::Git < Gem::Source -1 when Gem::Source then 1 - else - nil end end def ==(other) # :nodoc: - super and - @name == other.name and - @repository == other.repository and - @reference == other.reference and + super && + @name == other.name && + @repository == other.repository && + @reference == other.reference && @need_submodules == other.need_submodules end @@ -92,18 +90,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, "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, "fetch", "--quiet", "--force", "--tags", install_dir - success = system @git, 'reset', '--quiet', '--hard', rev_parse + success = system @git, "reset", "--quiet", "--hard", rev_parse if @need_submodules require "open3" - _, status = Open3.capture2e(@git, 'submodule', 'update', '--quiet', '--init', '--recursive') + _, status = Open3.capture2e(@git, "submodule", "update", "--quiet", "--init", "--recursive") success &&= status.success? end @@ -120,11 +118,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', - @repository, 'refs/heads/*:refs/heads/*' + system @git, "fetch", "--quiet", "--force", "--tags", + @repository, "refs/heads/*:refs/heads/*" end else - system @git, 'clone', '--quiet', '--bare', '--no-hardlinks', + system @git, "clone", "--quiet", "--bare", "--no-hardlinks", @repository, repo_cache_dir end end @@ -133,7 +131,7 @@ class Gem::Source::Git < Gem::Source # Directory where git gems get unpacked and so-forth. def base_dir # :nodoc: - File.join @root_dir, 'bundler' + File.join @root_dir, "bundler" end ## @@ -155,11 +153,11 @@ class Gem::Source::Git < Gem::Source def install_dir # :nodoc: return unless File.exist? repo_cache_dir - File.join base_dir, 'gems', "#{@name}-#{dir_shortref}" + File.join base_dir, "gems", "#{@name}-#{dir_shortref}" end def pretty_print(q) # :nodoc: - q.group 2, '[Git: ', ']' do + q.group 2, "[Git: ", "]" do q.breakable q.text @repository @@ -172,7 +170,7 @@ class Gem::Source::Git < Gem::Source # The directory where the git gem's repository will be cached. def repo_cache_dir # :nodoc: - File.join @root_dir, 'cache', 'bundler', 'git', "#{@name}-#{uri_hash}" + File.join @root_dir, "cache", "bundler", "git", "#{@name}-#{uri_hash}" end ## @@ -182,7 +180,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, "rev-parse", @reference).strip end raise Gem::Exception, @@ -201,7 +199,7 @@ class Gem::Source::Git < Gem::Source return [] unless install_dir Dir.chdir install_dir do - Dir['{,*,*/*}.gemspec'].map do |spec_file| + Dir["{,*,*/*}.gemspec"].map do |spec_file| directory = File.dirname spec_file file = File.basename spec_file @@ -211,7 +209,7 @@ class Gem::Source::Git < Gem::Source spec.base_dir = base_dir spec.extension_dir = - File.join base_dir, 'extensions', Gem::Platform.local.to_s, + File.join base_dir, "extensions", Gem::Platform.local.to_s, Gem.extension_api_version, "#{name}-#{dir_shortref}" spec.full_gem_path = File.dirname spec.loaded_from if spec @@ -223,14 +221,14 @@ class Gem::Source::Git < Gem::Source 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' + 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 7e1dd7af5a..cbe12a0516 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. @@ -20,8 +21,6 @@ class Gem::Source::Installed < Gem::Source 0 when Gem::Source then 1 - else - nil end end @@ -33,6 +32,6 @@ class Gem::Source::Installed < Gem::Source end def pretty_print(q) # :nodoc: - q.text '[Installed]' + q.text "[Installed]" end end diff --git a/lib/rubygems/source/local.rb b/lib/rubygems/source/local.rb index 078b06203f..d81d8343a8 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. @@ -23,14 +24,12 @@ class Gem::Source::Local < Gem::Source 0 when Gem::Source then 1 - else - nil end end def inspect # :nodoc: - keys = @specs ? @specs.keys.sort : 'NOT LOADED' - "#<%s specs: %p>" % [self.class, keys] + keys = @specs ? @specs.keys.sort : "NOT LOADED" + format("#<%s specs: %p>", self.class, keys) end def load_specs(type) # :nodoc: @@ -40,36 +39,35 @@ class Gem::Source::Local < Gem::Source @specs = {} Dir["*.gem"].each do |file| - begin - pkg = Gem::Package.new(file) - rescue SystemCallError, Gem::Package::FormatError - # ignore - else - tup = pkg.spec.name_tuple - @specs[tup] = [File.expand_path(file), pkg] - - case type - when :released - unless pkg.spec.version.prerelease? - names << pkg.spec.name_tuple - end - when :prerelease - if pkg.spec.version.prerelease? - names << pkg.spec.name_tuple - end - when :latest - tup = pkg.spec.name_tuple - - cur = names.find {|x| x.name == tup.name } - if !cur - names << tup - elsif cur.version < tup.version - names.delete cur - names << tup - end - else + pkg = Gem::Package.new(file) + spec = pkg.spec + rescue SystemCallError, Gem::Package::FormatError + # ignore + else + tup = spec.name_tuple + @specs[tup] = [File.expand_path(file), pkg] + + case type + when :released + unless pkg.spec.version.prerelease? + names << pkg.spec.name_tuple + end + when :prerelease + if pkg.spec.version.prerelease? names << pkg.spec.name_tuple end + when :latest + tup = pkg.spec.name_tuple + + cur = names.find {|x| x.name == tup.name } + if !cur + names << tup + elsif cur.version < tup.version + names.delete cur + names << tup + end + else + names << pkg.spec.name_tuple end end @@ -77,27 +75,25 @@ class Gem::Source::Local < Gem::Source end end - def find_gem(gem_name, version = Gem::Requirement.default, # :nodoc: - prerelease = false) + def find_gem(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.max_by(&:version) end def fetch_spec(name) # :nodoc: @@ -113,7 +109,7 @@ class Gem::Source::Local < Gem::Source def download(spec, cache_dir = nil) # :nodoc: load_specs :complete - @specs.each do |name, data| + @specs.each do |_name, data| return data[0] if data[1].spec == spec end @@ -121,7 +117,7 @@ class Gem::Source::Local < Gem::Source end def pretty_print(q) # :nodoc: - q.group 2, '[Local gems:', ']' do + q.group 2, "[Local gems:", "]" do q.breakable q.seplist @specs.keys do |v| q.text v.full_name diff --git a/lib/rubygems/source/lock.rb b/lib/rubygems/source/lock.rb index 49f097467b..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 @@ -24,13 +25,11 @@ class Gem::Source::Lock < Gem::Source @wrapped <=> other.wrapped when Gem::Source then 1 - else - nil end end def ==(other) # :nodoc: - 0 == (self <=> other) + (self <=> other) == 0 end def hash # :nodoc: diff --git a/lib/rubygems/source/specific_file.rb b/lib/rubygems/source/specific_file.rb index 24db1440dd..e9b2753646 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,7 +42,7 @@ class Gem::Source::SpecificFile < Gem::Source end def pretty_print(q) # :nodoc: - q.group 2, '[SpecificFile:', ']' do + q.group 2, "[SpecificFile:", "]" do q.breakable q.text @path end diff --git a/lib/rubygems/source/vendor.rb b/lib/rubygems/source/vendor.rb index 543acf1388..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. @@ -18,8 +19,6 @@ class Gem::Source::Vendor < Gem::Source::Installed 0 when Gem::Source then 1 - else - nil end end end |