class Gem::Mirror

Constants

DEFAULT_TO
DEFAULT_URI
RUBY
SPECS_FILES
VERSION

Public Class Methods

new(from = DEFAULT_URI, to = DEFAULT_TO, parallelism = nil, retries = nil, skiperror = nil) click to toggle source
# File lib/rubygems/mirror.rb, line 17
def initialize(from = DEFAULT_URI, to = DEFAULT_TO, parallelism = nil, retries = nil, skiperror = nil)
  @from, @to = from, to
  @fetcher = Fetcher.new :retries => retries, :skiperror => skiperror
  @pool = Pool.new(parallelism || 10)
end

Public Instance Methods

delete_gems() { || ... } click to toggle source
# File lib/rubygems/mirror.rb, line 95
def delete_gems
  gems_to_delete.each do |g|
    @pool.job do
      File.delete(to('gems', g))
      yield if block_given?
    end
  end

  @pool.run_til_done
end
existing_gems() click to toggle source
# File lib/rubygems/mirror.rb, line 57
def existing_gems
  Dir[to('gems', '*.gem')].entries.map { |f| File.basename(f) }
end
existing_gemspecs() click to toggle source
# File lib/rubygems/mirror.rb, line 61
def existing_gemspecs
  Dir[to("quick/Marshal.#{Gem.marshal_version}", '*.rz')].entries.map { |f| File.basename(f) }
end
from(*args) click to toggle source
# File lib/rubygems/mirror.rb, line 23
def from(*args)
  File.join(@from, *args)
end
gems() click to toggle source
# File lib/rubygems/mirror.rb, line 41
def gems
  gems = []

  SPECS_FILES.each do |sf|
    update_specs unless File.exist?(to(sf))

    gems += Marshal.load(File.read(to(sf)))
  end

  gems.map! do |name, ver, plat|
    # If the platform is ruby, it is not in the gem name
    "#{name}-#{ver}#{"-#{plat}" unless plat == RUBY}.gem"
  end
  gems
end
gems_to_delete() click to toggle source
# File lib/rubygems/mirror.rb, line 73
def gems_to_delete
  existing_gems - gems
end
gems_to_fetch() click to toggle source
# File lib/rubygems/mirror.rb, line 65
def gems_to_fetch
  gems - existing_gems
end
gemspecs_to_fetch() click to toggle source
# File lib/rubygems/mirror.rb, line 69
def gemspecs_to_fetch
  gems.map { |g| "#{g}spec.rz" } - existing_gemspecs
end
to(*args) click to toggle source
# File lib/rubygems/mirror.rb, line 27
def to(*args)
  File.join(@to, *args)
end
update() click to toggle source
# File lib/rubygems/mirror.rb, line 106
def update
  update_specs
  update_gems
  cleanup_gems
end
update_gems() { || ... } click to toggle source
# File lib/rubygems/mirror.rb, line 77
def update_gems
  gems_to_fetch.each do |g|
    @pool.job do
      @fetcher.fetch(from('gems', g), to('gems', g))
      yield if block_given?
    end
  end

  gemspecs_to_fetch.each do |g_spec|
    @pool.job do
      @fetcher.fetch(from("quick/Marshal.#{Gem.marshal_version}", g_spec), to("quick/Marshal.#{Gem.marshal_version}", g_spec))
      yield if block_given?
    end
  end

  @pool.run_til_done
end
update_specs() click to toggle source
# File lib/rubygems/mirror.rb, line 31
def update_specs
  SPECS_FILES.each do |sf|
    sfz = "#{sf}.gz"

    specz = to(sfz)
    @fetcher.fetch(from(sfz), specz)
    open(to(sf), 'wb') { |f| f << Gem.gunzip(File.read(specz)) }
  end
end