Class: Stickler::Repository::Mirror

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logable
Defined in:
lib/stickler/repository/mirror.rb

Overview

A Mirror mirrors gems in a Repository::Remote to a Repository::Local All of the Repository::Api methods are delegated to the Local instance and a new method #mirror() is added to pull gems from a Remote location and store in the Local instance

Defined Under Namespace

Classes: ConflictError, NotFoundError

Instance Method Summary collapse

Methods included from Logable

#logger

Constructor Details

#initialize(root_dir) ⇒ Mirror

Returns a new instance of Mirror.



20
21
22
23
# File 'lib/stickler/repository/mirror.rb', line 20

def initialize( root_dir )
  @local_repo = ::Stickler::Repository::Local.new( root_dir )
  @remote_repos = {}
end

Instance Method Details

#mirror(host, spec) ⇒ Object

:call-seq:

repo.mirror( spec, host = "rubygems.org" ) -> SpecLite

Mirror the gem described by spec on the host. If no host is given, it is assumed to be rubygems.org/.

Raises:



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/stickler/repository/mirror.rb', line 37

def mirror( host, spec )
  specs = @local_repo.search_for( spec )
  raise ConflictError, "gem #{spec.full_name} already exists" unless specs.empty?

  repo = remote_repo_for( host )
  repo.open( spec ) do |io|
    @local_repo.add( io )
  end
  raise NotFoundError, "Unable to find gem #{spec.full_name} on #{host}" unless @local_repo.gem_file_exist?( spec )
  logger.info( "Downloaded #{spec.full_name} from #{host} and adding to repo" )
  return spec 
end

#remote_repo_for(host) ⇒ Object



50
51
52
# File 'lib/stickler/repository/mirror.rb', line 50

def remote_repo_for( host )
  @remote_repos[host] ||= ::Stickler::Repository::Remote.new( host, :debug => true )
end