Class: Gem::Resolver::GitSet

Inherits:
Set
  • Object
show all
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'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGitSet

:nodoc:



35
36
37
38
39
40
41
# File 'lib/rubygems/resolver/git_set.rb', line 35

def initialize # :nodoc:
  @git             = ENV['git'] || 'git'
  @need_submodules = {}
  @repositories    = {}
  @root_dir        = Gem.dir
  @specs           = {}
end

Instance Attribute Details

#need_submodulesObject (readonly)

Contains repositories needing submodules



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

def need_submodules
  @need_submodules
end

#repositoriesObject (readonly)

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



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

def repositories
  @repositories
end

#root_dirObject

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



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

def root_dir
  @root_dir
end

#specsObject (readonly)

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



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

def specs
  @specs
end

Instance Method Details

#add_git_gem(name, repository, reference, submodules) ⇒ Object

:nodoc:



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

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) ⇒ Object

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.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rubygems/resolver/git_set.rb', line 56

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) ⇒ Object

Finds all git gems matching req



77
78
79
80
81
82
83
# File 'lib/rubygems/resolver/git_set.rb', line 77

def find_all req
  prefetch nil

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

#prefetch(reqs) ⇒ Object

Prefetches specifications from the git repositories in this set.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rubygems/resolver/git_set.rb', line 88

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.specs.each do |spec|
      git_spec = Gem::Resolver::GitSpecification.new self, spec, source

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

#pretty_print(q) ⇒ Object

:nodoc:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/rubygems/resolver/git_set.rb', line 103

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