Class: Bundler::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, bindir) ⇒ Repository

Returns a new instance of Repository.



7
8
9
10
11
12
13
14
# File 'lib/bundler/repository.rb', line 7

def initialize(path, bindir)
  FileUtils.mkdir_p(path)

  @path   = Pathname.new(path)
  @bindir = Pathname.new(bindir)

  @cache = GemDirectorySource.new(:location => @path.join("cache"))
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/bundler/repository.rb', line 5

def path
  @path
end

Instance Method Details

#cache(*gemfiles) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/bundler/repository.rb', line 53

def cache(*gemfiles)
  FileUtils.mkdir_p(@path.join("cache"))
  gemfiles.each do |gemfile|
    Bundler.logger.info "Caching: #{File.basename(gemfile)}"
    FileUtils.cp(gemfile, @path.join("cache"))
  end
end

#download_path_for(type) ⇒ Object



93
94
95
# File 'lib/bundler/repository.rb', line 93

def download_path_for(type)
  @repos[type].download_path_for
end

#gemsObject



79
80
81
# File 'lib/bundler/repository.rb', line 79

def gems
  source_index.gems.values
end

#install(dependencies, sources, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bundler/repository.rb', line 16

def install(dependencies, sources, options = {})
  # TODO: clean this up
  sources.each do |s|
    s.repository = self
    s.local = options[:cached]
  end

  source_requirements = {}
  dependencies = dependencies.map do |dep|
    source_requirements[dep.name] = dep.source if dep.source
    dep.to_gem_dependency
  end

  # Check to see whether the existing cache meets all the requirements
  begin
    valid = nil
    # valid = Resolver.resolve(dependencies, [source_index], source_requirements)
  rescue Bundler::GemNotFound
  end

  sources = only_local(sources) if options[:cached]

  # Check the remote sources if the existing cache does not meet the requirements
  # or the user passed --update
  if options[:update] || !valid
    Bundler.logger.info "Calculating dependencies..."
    bundle = Resolver.resolve(dependencies, [@cache] + sources, source_requirements)
    download(bundle, options)
    do_install(bundle, options)
    valid = bundle
  end

  generate_bins(valid, options)
  cleanup(valid, options)
  configure(valid, options)
end

#outdated_gemsObject



83
84
85
# File 'lib/bundler/repository.rb', line 83

def outdated_gems
  source_index.outdated.sort
end

#prune(dependencies, sources) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bundler/repository.rb', line 61

def prune(dependencies, sources)
  sources.each do |s|
    s.repository = self
    s.local = true
  end

  sources = only_local(sources)
  bundle = Resolver.resolve(dependencies, [@cache] + sources)
  @cache.gems.each do |name, specs|
    specs.each do |spec|
      unless bundle.any? { |s| s.name == spec.name && s.version == spec.version }
        Bundler.logger.info "Pruning #{spec.name} (#{spec.version}) from the cache"
        FileUtils.rm @path.join("cache", "#{spec.full_name}.gem")
      end
    end
  end
end

#source_indexObject



87
88
89
90
91
# File 'lib/bundler/repository.rb', line 87

def source_index
  index = Gem::SourceIndex.from_gems_in(@path.join("specifications"))
  index.each { |n, spec| spec.loaded_from = @path.join("specifications", "#{spec.full_name}.gemspec") }
  index
end