Class | Gem::Commands::WhichCommand |
In: |
lib/rubygems/commands/which_command.rb
|
Parent: | Gem::Command |
EXT | = | %w[.rb .rbw .so .dll] |
# File lib/rubygems/commands/which_command.rb, line 8 8: def initialize 9: super 'which', 'Find the location of a library', 10: :search_gems_first => false, :show_all => false 11: 12: add_option '-a', '--[no-]all', 'show all matching files' do |show_all, options| 13: options[:show_all] = show_all 14: end 15: 16: add_option '-g', '--[no-]gems-first', 17: 'search gems before non-gems' do |gems_first, options| 18: options[:search_gems_first] = gems_first 19: end 20: end
# File lib/rubygems/commands/which_command.rb, line 34 34: def execute 35: searcher = Gem::GemPathSearcher.new 36: 37: options[:args].each do |arg| 38: dirs = $LOAD_PATH 39: spec = searcher.find arg 40: 41: if spec then 42: if options[:search_gems_first] then 43: dirs = gem_paths(spec) + $LOAD_PATH 44: else 45: dirs = $LOAD_PATH + gem_paths(spec) 46: end 47: 48: say "(checking gem #{spec.full_name} for #{arg})" if 49: Gem.configuration.verbose 50: end 51: 52: paths = find_paths arg, dirs 53: 54: if paths.empty? then 55: say "Can't find #{arg}" 56: else 57: say paths 58: end 59: end 60: end
# File lib/rubygems/commands/which_command.rb, line 62 62: def find_paths(package_name, dirs) 63: result = [] 64: 65: dirs.each do |dir| 66: EXT.each do |ext| 67: full_path = File.join dir, "#{package_name}#{ext}" 68: if File.exist? full_path then 69: result << full_path 70: return result unless options[:show_all] 71: end 72: end 73: end 74: 75: result 76: end