1. Gem::
  2. Commands::
  3. UnpackCommand

class Gem::Commands::UnpackCommand

Public Class Methods

Source
# File lib/rubygems/commands/unpack_command.rb, line 20definitializerequire"fileutils"super"unpack","Unpack an installed gem to the current directory",version:Gem::Requirement.default,target:Dir.pwdadd_option("--target=DIR","target directory for unpacking")do|value,options|options[:target] =valueendadd_option("--spec","unpack the gem specification")do|_value,options|options[:spec] =trueendadd_security_optionadd_version_optionend
Calls superclass methodGem::Command::new

Public Instance Methods

Source
# File lib/rubygems/commands/unpack_command.rb, line 48defdescription<<-EOFThe unpack command allows you to examine the contents of a gem or modifythem to help diagnose a bug.You can add the contents of the unpacked gem to the load path using theRUBYLIB environment variable or -I:  $ gem unpack my_gem  Unpacked gem: '.../my_gem-1.0'  [edit my_gem-1.0/lib/my_gem.rb]  $ ruby -Imy_gem-1.0/lib -S other_programYou can repackage an unpacked gem using the build command.  See the buildcommand help for an example.    EOFend
Source
# File lib/rubygems/commands/unpack_command.rb, line 75defexecutesecurity_policy =options[:security_policy]get_all_gem_names.eachdo|name|dependency =Gem::Dependency.newname,options[:version]path =get_pathdependencyunlesspathalert_error"Gem '#{name}' not installed nor fetchable."nextendif@options[:spec]spec,metadata =Gem::Package.raw_spec(path,security_policy)ifmetadata.nil?alert_error"--spec is unsupported on '#{name}' (old format gem)"nextendspec_file =File.basenamespec.spec_fileFileUtils.mkdir_p@options[:target]if@options[:target]destination =if@options[:target]File.join@options[:target],spec_fileelsespec_fileendFile.opendestination,"w"do|io|io.writemetadataendelsebasename =File.basenamepath,".gem"target_dir =File.expand_pathbasename,options[:target]package =Gem::Package.newpath,security_policypackage.extract_filestarget_dirsay"Unpacked gem: '#{target_dir}'"endendend
Source
# File lib/rubygems/commands/unpack_command.rb, line 127deffind_in_cache(filename)Gem.path.eachdo|path|this_path =File.join(path,"cache",filename)returnthis_pathifFile.exist?this_pathendnilend

Find cached filename inGem.path. Returns nil if the file cannot be found.

Source
# File lib/rubygems/commands/unpack_command.rb, line 147defget_path(dependency)returndependency.nameif/\.gem$/i.match?(dependency.name)specs =dependency.matching_specsselected =specs.max_by(&:version)returnGem::RemoteFetcher.fetcher.download_to_cache(dependency)unlessselectedreturnunless/^#{selected.name}$/i.match?(dependency.name)# We expect to find (basename).gem in the 'cache' directory.  Furthermore,# the name match must be exact (ignoring case).path =find_in_cacheFile.basenameselected.cache_filereturnGem::RemoteFetcher.fetcher.download_to_cache(dependency)unlesspathpathend

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'# nilget_path'rak'# nil (exact name required)