| 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, :prefix => true
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::Specification.dirs
56: "default gem paths"
57: else
58: "specified path"
59: end
60:
61: gem_names = if options[:all] then
62: Gem::Specification.map(&:name)
63: else
64: get_all_gem_names
65: end
66:
67: gem_names.each do |name|
68: # HACK: find_by_name fails for some reason... ARGH
69: # How many places must we embed our resolve logic?
70: spec = Gem::Specification.find_all_by_name(name, version).last
71:
72: unless 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: gem_path = spec.full_gem_path
84: extra = "/{#{spec.require_paths.join ','}}" if options[:lib_only]
85: glob = "#{gem_path}#{extra}/**/*"
86: files = Dir[glob]
87:
88: gem_path = File.join gem_path, '' # add trailing / if missing
89:
90: files.sort.each do |file|
91: next if File.directory? file
92:
93: file = file.sub gem_path, '' unless options[:prefix]
94:
95: say file
96: end
97: end
98: end