class Bundler::Source::Rubygems

TODO: Refactor this class

Constants

FORCE_MODERN_INDEX_LIMIT

Attributes

caches[R]
dependency_names[RW]
remotes[R]

Public Class Methods

from_lock(options) click to toggle source
# File lib/bundler/source.rb, line 51
def self.from_lock(options)
  s = new(options)
  Array(options["remote"]).each { |r| s.add_remote(r) }
  s
end
new(options = {}) click to toggle source
# File lib/bundler/source.rb, line 18
def initialize(options = {})
  @options = options
  @remotes = (options["remotes"] || []).map { |r| normalize_uri(r) }
  @fetchers = {}
  @allow_remote = false
  @allow_cached = false

  @caches = [ Bundler.app_cache ] +
    Bundler.rubygems.gem_path.map{|p| File.expand_path("#{p}/cache") }
end

Public Instance Methods

==(o) click to toggle source
Alias for: eql?
add_remote(source) click to toggle source
# File lib/bundler/source.rb, line 126
def add_remote(source)
  @remotes << normalize_uri(source)
end
cache(spec) click to toggle source
# File lib/bundler/source.rb, line 118
def cache(spec)
  cached_path = cached_gem(spec)
  raise GemNotFound, "Missing gem file '#{spec.full_name}.gem'." unless cached_path
  return if File.dirname(cached_path) == Bundler.app_cache.to_s
  Bundler.ui.info "  * #{File.basename(cached_path)}"
  FileUtils.cp(cached_path, Bundler.app_cache)
end
cached!() click to toggle source
# File lib/bundler/source.rb, line 33
def cached!
  @allow_cached = true
end
eql?(o) click to toggle source
# File lib/bundler/source.rb, line 41
def eql?(o)
  Rubygems === o
end
Also aliased as: ==
hash() click to toggle source
# File lib/bundler/source.rb, line 37
def hash
  Rubygems.hash
end
install(spec) click to toggle source
# File lib/bundler/source.rb, line 73
def install(spec)
  if installed_specs[spec].any?
    Bundler.ui.info "Using #{spec.name} (#{spec.version}) "
    return
  end

  Bundler.ui.info "Installing #{spec.name} (#{spec.version}) "
  path = cached_gem(spec)
  if Bundler.requires_sudo?
    install_path = Bundler.tmp
    bin_path     = install_path.join("bin")
  else
    install_path = Bundler.rubygems.gem_dir
    bin_path     = Bundler.system_bindir
  end

  Bundler.rubygems.preserve_paths do
    Bundler::GemInstaller.new(path,
      :install_dir         => install_path.to_s,
      :bin_dir             => bin_path.to_s,
      :ignore_dependencies => true,
      :wrappers            => true,
      :env_shebang         => true
    ).install
  end

  if spec.post_install_message
    Installer.post_install_messages[spec.name] = spec.post_install_message
  end

  # SUDO HAX
  if Bundler.requires_sudo?
    Bundler.mkdir_p "#{Bundler.rubygems.gem_dir}/gems"
    Bundler.mkdir_p "#{Bundler.rubygems.gem_dir}/specifications"
    Bundler.sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Bundler.rubygems.gem_dir}/gems/"
    Bundler.sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Bundler.rubygems.gem_dir}/specifications/"
    spec.executables.each do |exe|
      Bundler.mkdir_p Bundler.system_bindir
      Bundler.sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Bundler.system_bindir}"
    end
  end

  spec.loaded_from = "#{Bundler.rubygems.gem_dir}/specifications/#{spec.full_name}.gemspec"
end
name() click to toggle source
Alias for: to_s
options() click to toggle source
# File lib/bundler/source.rb, line 47
def options
  { "remotes" => @remotes.map { |r| r.to_s } }
end
remote!() click to toggle source
# File lib/bundler/source.rb, line 29
def remote!
  @allow_remote = true
end
replace_remotes(source) click to toggle source
# File lib/bundler/source.rb, line 130
def replace_remotes(source)
  return false if source.remotes == @remotes

  @remotes = []
  source.remotes.each do |r|
    add_remote r.to_s
  end

  true
end
specs() click to toggle source
# File lib/bundler/source.rb, line 69
def specs
  @specs ||= fetch_specs
end
to_lock() click to toggle source
# File lib/bundler/source.rb, line 57
def to_lock
  out = "GEM\n"
  out << remotes.map {|r| "  remote: #{r}\n" }.join
  out << "  specs:\n"
end
to_s() click to toggle source
# File lib/bundler/source.rb, line 63
def to_s
  remote_names = self.remotes.map { |r| r.to_s }.join(', ')
  "rubygems repository #{remote_names}"
end
Also aliased as: name