Class Gem::Commands::FetchCommand
In: lib/rubygems/commands/fetch_command.rb
Parent: Gem::Command

Methods

execute   new  

Included Modules

Gem::LocalRemoteOptions Gem::VersionOption

Public Class methods

[Source]

    # File lib/rubygems/commands/fetch_command.rb, line 10
10:   def initialize
11:     super 'fetch', 'Download a gem and place it in the current directory'
12: 
13:     add_bulk_threshold_option
14:     add_proxy_option
15:     add_source_option
16:     add_clear_sources_option
17: 
18:     add_version_option
19:     add_platform_option
20:     add_prerelease_option
21:   end

Public Instance methods

[Source]

    # File lib/rubygems/commands/fetch_command.rb, line 35
35:   def execute
36:     version = options[:version] || Gem::Requirement.default
37:     all = Gem::Requirement.default != version
38: 
39:     platform  = Gem.platforms.last
40:     gem_names = get_all_gem_names
41: 
42:     gem_names.each do |gem_name|
43:       dep = Gem::Dependency.new gem_name, version
44:       dep.prerelease = options[:prerelease]
45: 
46:       specs_and_sources, errors =
47:         Gem::SpecFetcher.fetcher.fetch_with_errors(dep, all, true,
48:                                                    dep.prerelease?)
49: 
50:       if platform then
51:         filtered = specs_and_sources.select { |s,| s.platform == platform }
52:         specs_and_sources = filtered unless filtered.empty?
53:       end
54: 
55:       spec, source_uri = specs_and_sources.sort_by { |s,| s.version }.last
56: 
57:       if spec.nil? then
58:         show_lookup_failure gem_name, version, errors, options[:domain]
59:         next
60:       end
61: 
62:       file = "#{spec.full_name}.gem"
63:       remote_path = URI.parse(source_uri) + "gems/#{file}"
64: 
65:       fetch = Gem::RemoteFetcher.fetcher
66: 
67:       gem = fetch.fetch_path remote_path.to_s
68: 
69:       File.open file, "wb" do |f|
70:         f.write gem
71:       end
72: 
73:       say "Downloaded #{spec.full_name}"
74:     end
75:   end

[Validate]