| Class | Gem::Commands::ContentsCommand |
| In: |
lib/rubygems/commands/contents_command.rb
|
| Parent: | Gem::Command |
# File lib/rubygems/commands/contents_command.rb, line 8
8: def initialize
9: super 'contents', 'Display the contents of the installed gems',
10: :specdirs => [], :lib_only => false
11:
12: add_version_option
13:
14: add_option( '--all',
15: "Contents for all gems") do |all, options|
16: options[:all] = all
17: end
18:
19: add_option('-s', '--spec-dir a,b,c', Array,
20: "Search for gems under specific paths") do |spec_dirs, options|
21: options[:specdirs] = spec_dirs
22: end
23:
24: add_option('-l', '--[no-]lib-only',
25: "Only return files in the Gem's lib_dirs") do |lib_only, options|
26: options[:lib_only] = lib_only
27: end
28:
29: add_option( '--[no-]prefix',
30: "Don't include installed path prefix") do |prefix, options|
31: options[:prefix] = prefix
32: end
33: end
# File lib/rubygems/commands/contents_command.rb, line 47
47: def execute
48: version = options[:version] || Gem::Requirement.default
49:
50: spec_dirs = options[:specdirs].map do |i|
51: [i, File.join(i, "specifications")]
52: end.flatten
53:
54: path_kind = if spec_dirs.empty? then
55: spec_dirs = Gem::SourceIndex.installed_spec_directories
56: "default gem paths"
57: else
58: "specified path"
59: end
60:
61: si = Gem::SourceIndex.from_gems_in(*spec_dirs)
62:
63: gem_names = if options[:all] then
64: si.map { |_, spec| spec.name }
65: else
66: get_all_gem_names
67: end
68:
69: gem_names.each do |name|
70: gem_spec = si.find_name(name, version).last
71:
72: unless gem_spec then
73: say "Unable to find gem '#{name}' in #{path_kind}"
74:
75: if Gem.configuration.verbose then
76: say "\nDirectories searched:"
77: spec_dirs.each { |dir| say dir }
78: end
79:
80: terminate_interaction 1 if gem_names.length == 1
81: end
82:
83: files = options[:lib_only] ? gem_spec.lib_files : gem_spec.files
84:
85: files.each do |f|
86: path = if options[:prefix] then
87: File.join gem_spec.full_gem_path, f
88: else
89: f
90: end
91:
92: say path
93: end
94: end
95: end