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

Attributes inherited from Set

#errors, #prerelease, #remote

Instance Method Summary collapse

Methods inherited from Set

#remote?

Constructor Details

#initializeGitSet

:nodoc:


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

def initialize # :nodoc:
  super()

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

Instance Attribute Details

#need_submodulesObject (readonly)

Contains repositories needing submodules


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

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.


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

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.


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

def root_dir
  @root_dir
end

#specsObject (readonly)

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


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

def specs
  @specs
end

Instance Method Details

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

:nodoc:


46
47
48
49
# File 'lib/rubygems/resolver/git_set.rb', line 46

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.


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

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


80
81
82
83
84
85
86
# File 'lib/rubygems/resolver/git_set.rb', line 80

def find_all(req)
  prefetch nil

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

#prefetch(reqs) ⇒ Object

Prefetches specifications from the git repositories in this set.


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rubygems/resolver/git_set.rb', line 91

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

:nodoc:


107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rubygems/resolver/git_set.rb', line 107

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