Parent

Gem::Mirror

Public Class Methods

new(from = DEFAULT_URI, to = DEFAULT_TO, parallelism = 10) click to toggle source
# File lib/rubygems/mirror.rb, line 18
def initialize(from = DEFAULT_URI, to = DEFAULT_TO, parallelism = 10)
  @from, @to = from, to
  @fetcher = Fetcher.new
  @pool = Pool.new(parallelism)
end

Public Instance Methods

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

  @pool.run_til_done
end
existing_gems() click to toggle source
# File lib/rubygems/mirror.rb, line 49
def existing_gems
  Dir[to('gems', '*.gem')].entries.map { |f| File.basename(f) }
end
from(*args) click to toggle source
# File lib/rubygems/mirror.rb, line 24
def from(*args)
  File.join(@from, *args)
end
gems() click to toggle source
# File lib/rubygems/mirror.rb, line 38
def gems
  update_specs unless File.exists?(to(SPECS_FILE))

  gems = Marshal.load(File.read(to(SPECS_FILE)))
  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 57
def gems_to_delete
  existing_gems - gems
end
gems_to_fetch() click to toggle source
# File lib/rubygems/mirror.rb, line 53
def gems_to_fetch
  gems - existing_gems
end
to(*args) click to toggle source
# File lib/rubygems/mirror.rb, line 28
def to(*args)
  File.join(@to, *args)
end
update() click to toggle source
# File lib/rubygems/mirror.rb, line 83
def update
  update_specs
  update_gems
  cleanup_gems
end
update_gems() click to toggle source
# File lib/rubygems/mirror.rb, line 61
def update_gems
  gems_to_fetch.each do |g|
    @pool.job do
      @fetcher.fetch(from('gems', g), to('gems', g))
      yield
    end
  end

  @pool.run_til_done
end
update_specs() click to toggle source
# File lib/rubygems/mirror.rb, line 32
def update_specs
  specz = to(SPECS_FILE_Z)
  @fetcher.fetch(from(SPECS_FILE_Z), specz)
  open(to(SPECS_FILE), 'wb') { |f| f << Gem.gunzip(File.read(specz)) }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.