Class: Stickler::Middleware::Mirror

Inherits:
Index
  • Object
show all
Defined in:
lib/stickler/middleware/mirror.rb

Overview

A Mirror server keeps gems from one or more upstream gem servers in local repositories.

Options

:serve_indexes

the same as the Index middleware

:repo_root

The path that is to be the root of the Repository instance managed by this server.

The :repo_root option is required.

Usage

use Stickler::Middleware::Mirror, :repo_root => '/path/to/repository'

use Stickler::Middleware::Mirror, :repo_root => '/path/to/repository',
                                  :serve_indexes => true

Constant Summary

Constants inherited from Index

Index::NAME_VERSION_PLATFORM_REGEX

Instance Attribute Summary

Attributes inherited from Index

#repo

Instance Method Summary collapse

Methods inherited from Index

#marshal, #marshalled_specs, #optimize_specs, #serve_indexes, #to_compression_flag

Methods included from Logable

#logger

Methods included from Helpers::Specs

#collect_specs_via, #latest_specs, #prerelease_specs, #released_specs, #specs, #specs_by_first_upcase_char, #specs_by_name, #specs_by_repo, #specs_grouped_by_name

Methods included from Helpers::Compression

#compression, #compression=

Constructor Details

#initialize(app, options = {}) ⇒ Mirror

Returns a new instance of Mirror.



24
25
26
27
# File 'lib/stickler/middleware/mirror.rb', line 24

def initialize( app, options = {} )
  super( app )
  @repo = ::Stickler::Repository::Mirror.new( options[:repo_root] )
end

Instance Method Details

#manage(params) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/stickler/middleware/mirror.rb', line 29

def manage( params )
  host = params[:source]
  spec = Stickler::SpecLite.new( params[:name], params[:version], params[:platform] )

  begin
    if spec = @repo.mirror( host , spec ) then
      logger.info("Mirrored #{spec.file_name}")
      status 201
      response["Location"] = "/gems/#{spec.file_name}"
      nil
    else
      logger.info( "Unable to find #{spec.full_name} at #{host}" )
      not_found "Unable to find gem [#{spec.full_name}] at source #{host}"
    end
  rescue ::Stickler::Repository::Mirror::ConflictError => ce
    logger.error( ce.message )
    error( 409, ce.message )
  rescue ::Stickler::Repository::Mirror::NotFoundError => nfe
    logger.error( nfe.message )
    not_found nfe.message
  end
end