~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to lib/rubygems/commands/fetch_command.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'rubygems/command'
 
2
require 'rubygems/local_remote_options'
 
3
require 'rubygems/version_option'
 
4
require 'rubygems/source_info_cache'
 
5
 
 
6
class Gem::Commands::FetchCommand < Gem::Command
 
7
 
 
8
  include Gem::LocalRemoteOptions
 
9
  include Gem::VersionOption
 
10
 
 
11
  def initialize
 
12
    super 'fetch', 'Download a gem and place it in the current directory'
 
13
 
 
14
    add_bulk_threshold_option
 
15
    add_proxy_option
 
16
    add_source_option
 
17
 
 
18
    add_version_option
 
19
    add_platform_option
 
20
  end
 
21
 
 
22
  def arguments # :nodoc:
 
23
    'GEMNAME       name of gem to download'
 
24
  end
 
25
 
 
26
  def defaults_str # :nodoc:
 
27
    "--version '#{Gem::Requirement.default}'"
 
28
  end
 
29
 
 
30
  def usage # :nodoc:
 
31
    "#{program_name} GEMNAME [GEMNAME ...]"
 
32
  end
 
33
 
 
34
  def execute
 
35
    version = options[:version] || Gem::Requirement.default
 
36
 
 
37
    gem_names = get_all_gem_names
 
38
 
 
39
    gem_names.each do |gem_name|
 
40
      dep = Gem::Dependency.new gem_name, version
 
41
      specs_and_sources = Gem::SourceInfoCache.search_with_source dep, true
 
42
 
 
43
      specs_and_sources.sort_by { |spec,| spec.version }
 
44
 
 
45
      spec, source_uri = specs_and_sources.last
 
46
 
 
47
      gem_file = "#{spec.full_name}.gem"
 
48
 
 
49
      gem_path = File.join source_uri, 'gems', gem_file
 
50
 
 
51
      gem = Gem::RemoteFetcher.fetcher.fetch_path gem_path
 
52
 
 
53
      File.open gem_file, 'wb' do |fp|
 
54
        fp.write gem
 
55
      end
 
56
 
 
57
      say "Downloaded #{gem_file}"
 
58
    end
 
59
  end
 
60
 
 
61
end
 
62