Class: Gem::Source::Git
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Gem::Source
|
|
Instance Chain:
self,
::Gem::Source ,
::Gem::Text ,
Comparable
|
|
Inherits: |
Gem::Source
|
Defined in: | lib/rubygems/source/git.rb |
Overview
Constant Summary
::Gem::Source
- Inherited
Class Method Summary
-
.new(name, repository, reference, submodules = false) ⇒ Git
constructor
Creates a new git gem source for a gems from loaded from #repository at the given #reference.
::Gem::Source
- Inherited
.new | Creates a new |
Instance Attribute Summary
-
#name
readonly
The name of the gem created by this git gem.
-
#need_submodules
readonly
Does this repository need submodules checked out too?
-
#reference
readonly
The commit reference used for checking out this git gem.
-
#remote
rw
When false the cache for this repository will not be updated.
-
#repository
readonly
The git repository this gem is sourced from.
-
#root_dir
rw
The directory for cache and git gem installation.
::Gem::Source
- Inherited
#update_cache? | Returns true when it is possible and safe to update the cache directory. |
#uri | The URI this source will fetch gems from. |
Instance Method Summary
- #<=>(other)
-
#specs
Loads all gemspecs in the repository.
- #==(other) Internal use only
-
#base_dir
Internal use only
Directory where git gems get unpacked and so-forth.
-
#cache
Internal use only
Creates a local cache repository for the git gem.
-
#checkout
Internal use only
Checks out the files for the repository into the install_dir.
-
#dir_shortref
Internal use only
A short reference for use in git gem directories.
-
#download(full_spec, path)
Internal use only
Nothing to download for git gems.
-
#install_dir
Internal use only
The directory where the git gem will be installed.
- #pretty_print(q) Internal use only
-
#repo_cache_dir
Internal use only
The directory where the git gem’s repository will be cached.
-
#rev_parse
Internal use only
Converts the git reference for the repository into a commit hash.
-
#uri_hash
Internal use only
A hash for the git gem based on the git repository
::Gem::URI
.
::Gem::Source
- Inherited
#<=> | Sources are ordered by installation preference. |
#cache_dir | Returns the local directory to write #uri to. |
#download | Downloads |
#fetch_spec | Fetches a specification for the given |
#load_specs | Loads |
#typo_squatting?, #enforce_trailing_slash, #==, | |
#dependency_resolver_set | Returns a Set that can fetch specifications from this source. |
#eql? | Alias for #==. |
#hash, #pretty_print |
::Gem::Text
- Included
#clean_text | Remove any non-printable characters and make the text suitable for printing. |
#format_text | Wraps |
#levenshtein_distance | Returns a value representing the “cost” of transforming str1 into str2 Vendored version of |
#truncate_text, #min3 |
Constructor Details
.new(name, repository, reference, submodules = false) ⇒ Git
Creates a new git gem source for a gems from loaded from #repository at the given #reference. The #name is only used to track the repository back to a gem dependencies file, it has no real significance as a git repository may contain multiple gems. If submodules
is true, submodules will be checked out when the gem is installed.
# File 'lib/rubygems/source/git.rb', line 51
def initialize(name, repository, reference, submodules = false) require_relative "../uri" @uri = Gem::Uri.parse(repository) @name = name @repository = repository @reference = reference || "HEAD" @need_submodules = submodules @remote = true @root_dir = Gem.dir @git = ENV["git"] || "git" end
Instance Attribute Details
#name (readonly)
The name of the gem created by this git gem.
# File 'lib/rubygems/source/git.rb', line 17
attr_reader :name
#need_submodules (readonly)
Does this repository need submodules checked out too?
# File 'lib/rubygems/source/git.rb', line 42
attr_reader :need_submodules
#reference (readonly)
The commit reference used for checking out this git gem.
# File 'lib/rubygems/source/git.rb', line 22
attr_reader :reference
#remote (rw)
When false the cache for this repository will not be updated.
# File 'lib/rubygems/source/git.rb', line 27
attr_accessor :remote
#repository (readonly)
The git repository this gem is sourced from.
# File 'lib/rubygems/source/git.rb', line 32
attr_reader :repository
#root_dir (rw)
The directory for cache and git gem installation
# File 'lib/rubygems/source/git.rb', line 37
attr_accessor :root_dir
Instance Method Details
#<=>(other)
[ GitHub ]#==(other)
# File 'lib/rubygems/source/git.rb', line 76
def ==(other) # :nodoc: super && @name == other.name && @repository == other.repository && @reference == other.reference && @need_submodules == other.need_submodules end
#base_dir
Directory where git gems get unpacked and so-forth.
# File 'lib/rubygems/source/git.rb', line 133
def base_dir # :nodoc: File.join @root_dir, "bundler" end
#cache
Creates a local cache repository for the git gem.
# File 'lib/rubygems/source/git.rb', line 116
def cache # :nodoc: return unless @remote if File.exist? repo_cache_dir Dir.chdir repo_cache_dir do system @git, "fetch", "--quiet", "--force", "--tags", @repository, "refs/heads/*:refs/heads/*" end else system @git, "clone", "--quiet", "--bare", "--no-hardlinks", @repository, repo_cache_dir end end
#checkout
Checks out the files for the repository into the install_dir.
# File 'lib/rubygems/source/git.rb', line 87
def checkout # :nodoc: cache return false unless File.exist? repo_cache_dir unless File.exist? install_dir 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 success = system @git, "reset", "--quiet", "--hard", rev_parse if @need_submodules require "open3" _, status = Open3.capture2e(@git, "submodule", "update", "--quiet", "--init", "--recursive") success &&= status.success? end success end end
#dir_shortref
A short reference for use in git gem directories
# File 'lib/rubygems/source/git.rb', line 140
def dir_shortref # :nodoc: rev_parse[0..11] end
#download(full_spec, path)
Nothing to download for git gems
# File 'lib/rubygems/source/git.rb', line 147
def download(full_spec, path) # :nodoc: end
#install_dir
The directory where the git gem will be installed.
# File 'lib/rubygems/source/git.rb', line 153
def install_dir # :nodoc: return unless File.exist? repo_cache_dir File.join base_dir, "gems", "#{@name}-#{dir_shortref}" end
#pretty_print(q)
# File 'lib/rubygems/source/git.rb', line 159
def pretty_print(q) # :nodoc: q.object_group(self) do q.group 2, "[Git: ", "]" do q.breakable q.text @repository q.breakable q.text @reference end end end
#repo_cache_dir
The directory where the git gem’s repository will be cached.
# File 'lib/rubygems/source/git.rb', line 174
def repo_cache_dir # :nodoc: File.join @root_dir, "cache", "bundler", "git", "#{@name}-#{uri_hash}" end
#rev_parse
Converts the git reference for the repository into a commit hash.
#specs
Loads all gemspecs in the repository
# File 'lib/rubygems/source/git.rb', line 198
def specs checkout return [] unless install_dir Dir.chdir install_dir do Dir["{,*,*/*}.gemspec"].filter_map do |spec_file| directory = File.dirname spec_file file = File.basename spec_file Dir.chdir directory do spec = Gem::Specification.load file if spec spec.base_dir = base_dir spec.extension_dir = 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 end spec end end end end
#uri_hash
A hash for the git gem based on the git repository ::Gem::URI
.
# File 'lib/rubygems/source/git.rb', line 228
def uri_hash # :nodoc: require_relative "../openssl" normalized = if @repository.match?(%r{^\w://(\w@)?}) uri = Gem::URI(@repository).normalize.to_s.sub %r{/$},"" uri.sub(/\A(\w+)/) { $1.downcase } else @repository end OpenSSL::Digest::SHA1.hexdigest normalized end