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: 
17:     add_version_option
18:     add_platform_option
19:     add_prerelease_option
20:   end

Public Instance methods

[Source]

    # File lib/rubygems/commands/fetch_command.rb, line 34
34:   def execute
35:     version = options[:version] || Gem::Requirement.default
36:     all = Gem::Requirement.default != version
37: 
38:     platform  = Gem.platforms.last
39:     gem_names = get_all_gem_names
40: 
41:     gem_names.each do |gem_name|
42:       dep = Gem::Dependency.new gem_name, version
43:       dep.prerelease = options[:prerelease]
44: 
45:       specs_and_sources, errors =
46:         Gem::SpecFetcher.fetcher.fetch_with_errors(dep, all, true,
47:                                                    dep.prerelease?)
48: 
49:       if platform then
50:         filtered = specs_and_sources.select { |s,| s.platform == platform }
51:         specs_and_sources = filtered unless filtered.empty?
52:       end
53: 
54:       spec, source_uri = specs_and_sources.sort_by { |s,| s.version }.last
55: 
56:       if spec.nil? then
57:         show_lookup_failure gem_name, version, errors, options[:domain]
58:         next
59:       end
60: 
61:       path = Gem::RemoteFetcher.fetcher.download spec, source_uri
62:       FileUtils.mv path, spec.file_name
63: 
64:       say "Downloaded #{spec.full_name}"
65:     end
66:   end

[Validate]