Parent

Included Modules

Class Index [+]

Quicksearch

Gem::Commands::UnpackCommand

Public Class Methods

new() click to toggle source
    # File lib/rubygems/commands/unpack_command.rb, line 10
10:   def initialize
11:     super 'unpack', 'Unpack an installed gem to the current directory',
12:           :version => Gem::Requirement.default,
13:           :target  => Dir.pwd
14: 
15:     add_option('--target=DIR',
16:                'target directory for unpacking') do |value, options|
17:       options[:target] = value
18:     end
19: 
20:     add_version_option
21:   end

Public Instance Methods

download(dependency) click to toggle source
    # File lib/rubygems/commands/unpack_command.rb, line 35
35:   def download dependency
36:     found = Gem::SpecFetcher.fetcher.fetch dependency
37: 
38:     return if found.empty?
39: 
40:     spec, source_uri = found.first
41: 
42:     Gem::RemoteFetcher.fetcher.download spec, source_uri
43:   end
execute() click to toggle source
    # File lib/rubygems/commands/unpack_command.rb, line 50
50:   def execute
51:     get_all_gem_names.each do |name|
52:       dependency = Gem::Dependency.new name, options[:version]
53:       path = get_path dependency
54: 
55:       if path then
56:         basename = File.basename path, '.gem'
57:         target_dir = File.expand_path basename, options[:target]
58:         FileUtils.mkdir_p target_dir
59:         Gem::Installer.new(path, :unpack => true).unpack target_dir
60:         say "Unpacked gem: '#{target_dir}'"
61:       else
62:         alert_error "Gem '#{name}' not installed."
63:       end
64:     end
65:   end
get_path(dependency) click to toggle source

Return the full path to the cached gem file matching the given name and version requirement. Returns ‘nil’ if no match.

Example:

  get_path 'rake', '> 0.4' # "/usr/lib/ruby/gems/1.8/cache/rake-0.4.2.gem"
  get_path 'rake', '< 0.1' # nil
  get_path 'rak'           # nil (exact name required)
     # File lib/rubygems/commands/unpack_command.rb, line 84
 84:   def get_path dependency
 85:     return dependency.name if dependency.name =~ /\.gem$/
 86: 
 87:     specs = Gem.source_index.search dependency
 88: 
 89:     selected = specs.sort_by { |s| s.version }.last
 90: 
 91:     return download(dependency) if selected.nil?
 92: 
 93:     return unless dependency.name =~ /^#{selected.name}$/
 94: 
 95:     # We expect to find (basename).gem in the 'cache' directory.  Furthermore,
 96:     # the name match must be exact (ignoring case).
 97:     filename = selected.file_name
 98:     path = nil
 99: 
100:     Gem.path.find do |gem_dir|
101:       path = File.join gem_dir, 'cache', filename
102:       File.exist? path
103:     end
104: 
105:     path
106:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.