123456789_123456789_123456789_123456789_123456789_

Class: Gem::Resolver::GitSet

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Set
Instance Chain:
self, Set
Inherits: Gem::Resolver::Set
Defined in: lib/rubygems/resolver/git_set.rb

Overview

A GitSet represents gems that are sourced from git repositories.

This is used for gem dependency file support.

Example:

set = Gem::Resolver::GitSet.new
set.add_git_gem 'rake', 'git://example/rake.git', tag: 'rake-10.1.0'

Class Method Summary

Set - Inherited

Instance Attribute Summary

  • #root_dir rw

    The root directory for git gems in this set.

  • #need_submodules readonly Internal use only

    Contains repositories needing submodules.

  • #repositories readonly Internal use only

    A Hash containing git gem names for keys and a Hash of repository and git commit reference as values.

  • #specs readonly Internal use only

    A hash of gem names to Gem::Resolver::GitSpecifications

Set - Inherited

#errors

Errors encountered when resolving gems.

#prerelease

When true, allows matching of requests to prerelease gems.

#remote

Set to true to disable network access for this set.

#remote?

When true, this set is allowed to access the network when looking up specifications or dependencies.

Instance Method Summary

Set - Inherited

#find_all

The find_all method must be implemented.

#prefetch

The #prefetch method may be overridden, but this is not necessary.

Constructor Details

.newGitSet

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/git_set.rb', line 35

def initialize # :nodoc:
  super()

  @git             = ENV['git'] || 'git'
  @need_submodules = {}
  @repositories    = {}
  @root_dir        = Gem.dir
  @specs           = {}
end

Instance Attribute Details

#need_submodules (readonly)

This method is for internal use only.

Contains repositories needing submodules

[ GitHub ]

  
# File 'lib/rubygems/resolver/git_set.rb', line 22

attr_reader :need_submodules # :nodoc:

#repositories (readonly)

This method is for internal use only.

A Hash containing git gem names for keys and a Hash of repository and git commit reference as values.

[ GitHub ]

  
# File 'lib/rubygems/resolver/git_set.rb', line 28

attr_reader :repositories # :nodoc:

#root_dir (rw)

The root directory for git gems in this set. This is usually Gem.dir, the installation directory for regular gems.

[ GitHub ]

  
# File 'lib/rubygems/resolver/git_set.rb', line 17

attr_accessor :root_dir

#specs (readonly)

This method is for internal use only.

A hash of gem names to Gem::Resolver::GitSpecifications

[ GitHub ]

  
# File 'lib/rubygems/resolver/git_set.rb', line 33

attr_reader :specs # :nodoc:

Instance Method Details

#add_git_gem(name, repository, reference, submodules)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/git_set.rb', line 45

def add_git_gem(name, repository, reference, submodules) # :nodoc:
  @repositories[name] = [repository, reference]
  @need_submodules[repository] = submodules
end

#add_git_spec(name, version, repository, reference, submodules)

This method is for internal use only.

Adds and returns a GitSpecification with the given name and version which came from a repository at the given reference. If submodules is true they are checked out along with the repository.

This fills in the prefetch information as enough information about the gem is present in the arguments.

[ GitHub ]

  
# File 'lib/rubygems/resolver/git_set.rb', line 58

def add_git_spec(name, version, repository, reference, submodules) # :nodoc:
  add_git_gem name, repository, reference, submodules

  source = Gem::Source::Git.new name, repository, reference
  source.root_dir = @root_dir

  spec = Gem::Specification.new do |s|
    s.name    = name
    s.version = version
  end

  git_spec = Gem::Resolver::GitSpecification.new self, spec, source

  @specs[spec.name] = git_spec

  git_spec
end

#find_all(req)

Finds all git gems matching req

[ GitHub ]

  
# File 'lib/rubygems/resolver/git_set.rb', line 79

def find_all(req)
  prefetch nil

  specs.values.select do |spec|
    req.match? spec
  end
end

#prefetch(reqs)

Prefetches specifications from the git repositories in this set.

[ GitHub ]

  
# File 'lib/rubygems/resolver/git_set.rb', line 90

def prefetch(reqs)
  return unless @specs.empty?

  @repositories.each do |name, (repository, reference)|
    source = Gem::Source::Git.new name, repository, reference
    source.root_dir = @root_dir
    source.remote = @remote

    source.specs.each do |spec|
      git_spec = Gem::Resolver::GitSpecification.new self, spec, source

      @specs[spec.name] = git_spec
    end
  end
end

#pretty_print(q)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/git_set.rb', line 106

def pretty_print(q) # :nodoc:
  q.group 2, '[GitSet', ']' do
    next if @repositories.empty?
    q.breakable

    repos = @repositories.map do |name, (repository, reference)|
      "#{name}: #{repository}@#{reference}"
    end

    q.seplist repos do |repo|
      q.text repo
    end
  end
end