Class: Stickler::Client::Mirror
Instance Attribute Summary
#argv, #sources
Class Method Summary
collapse
Instance Method Summary
collapse
config, #initialize, #remote_repo_for
Class Method Details
.banner ⇒ Object
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/stickler/client/mirror.rb', line 4
def self.banner
<<-_
Pull a specific version of a gem from an upstream gem server
and store it in a stickler server.
Usage: stickler mirror [options] --gem-version x.y.z gem
Options:
_
end
|
Instance Method Details
#parse(argv) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/stickler/client/mirror.rb', line 25
def parse( argv )
gem_name = nil
opts = super( argv ) do |p|
raise Trollop::CommandlineError, "At least one gem is required to mirror" if p.leftovers.empty?
gem_name = p.leftovers.shift
end
opts[:gem_name] = gem_name
return opts
end
|
#parser ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/stickler/client/mirror.rb', line 15
def parser
unless @parser then
@parser = super
@parser.opt( :upstream, "The upstream gem server from which to pull", :type => :string, :default => Client.config.upstream )
@parser.opt( :gem_version, "The version of the gem to yank (required)", :type => :string, :required => true )
@parser.opt( :platform, "The platform of the gem to yank", :type => :string, :default => ::Gem::Platform::RUBY )
end
return @parser
end
|
#resource_uri(opts) ⇒ Object
35
36
37
|
# File 'lib/stickler/client/mirror.rb', line 35
def resource_uri( opts )
opts[:server] || Client.config.server
end
|
#run ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/stickler/client/mirror.rb', line 39
def run
opts = parse( self.argv )
repo = remote_repo_for( opts )
spec = Stickler::SpecLite.new( opts[:gem_name], opts[:gem_version], opts[:platform] )
upstream_host = Addressable::URI.parse( opts[:upstream] ).host
$stdout.write "Asking #{repo.uri} to mirror #{spec.full_name} from #{upstream_host} : "
$stdout.flush
uri = [ repo.uri.join( upstream_host ), opts[:gem_name], opts[:gem_version], opts[:platform] ].join("/")
resp = Excon.post( uri, :expects => [200, 201] )
$stdout.puts "OK -> #{repo.uri.join(resp.['Location'])}"
rescue Excon::Errors::Error => he
resp = he.response
$stdout.puts "ERROR -> #{resp.body}"
rescue StandardError => e
puts e.backtrace.join("\n")
$stdout.puts "ERROR -> #{e.message}"
end
|