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::SourceIndex.installed_spec_directories 56: "default gem paths" 57: else 58: "specified path" 59: end 60: 61: si = Gem::SourceIndex.new 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: spec = si.find_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