Class | RiDriver |
In: |
ri/ri_driver.rb
|
Parent: | Object |
# File ri/ri_driver.rb, line 14 14: def initialize 15: @options = RI::Options.instance 16: 17: args = ARGV 18: if ENV["RI"] 19: args = ENV["RI"].split.concat(ARGV) 20: end 21: 22: @options.parse(args) 23: 24: paths = @options.paths || RI::Paths::PATH 25: if paths.empty? 26: report_missing_documentation(paths) 27: end 28: @ri_reader = RI::RiReader.new(RI::RiCache.new(paths)) 29: @display = @options.displayer 30: end
# File ri/ri_driver.rb, line 86 86: def get_info_for(arg) 87: desc = NameDescriptor.new(arg) 88: 89: namespaces = @ri_reader.top_level_namespace 90: 91: for class_name in desc.class_names 92: namespaces = @ri_reader.lookup_namespace_in(class_name, namespaces) 93: if namespaces.empty? 94: raise RiError.new("Nothing known about #{arg}") 95: end 96: end 97: 98: # at this point, if we have multiple possible namespaces, but one 99: # is an exact match for our requested class, prune down to just it 100: 101: full_class_name = desc.full_class_name 102: entries = namespaces.find_all {|m| m.full_name == full_class_name} 103: namespaces = entries if entries.size == 1 104: 105: if desc.method_name.nil? 106: report_class_stuff(namespaces) 107: else 108: methods = @ri_reader.find_methods(desc.method_name, 109: desc.is_class_method, 110: namespaces) 111: 112: if methods.empty? 113: raise RiError.new("Nothing known about #{arg}") 114: else 115: report_method_stuff(desc.method_name, methods) 116: end 117: end 118: end
# File ri/ri_driver.rb, line 122 122: def process_args 123: if @options.list_classes 124: classes = @ri_reader.full_class_names 125: @display.list_known_classes(classes) 126: elsif @options.list_names 127: names = @ri_reader.all_names 128: @display.list_known_names(names) 129: else 130: if ARGV.size.zero? 131: @display.display_usage 132: else 133: begin 134: ARGV.each do |arg| 135: get_info_for(arg) 136: end 137: rescue RiError => e 138: STDERR.puts(e.message) 139: exit(1) 140: end 141: end 142: end 143: end
# File ri/ri_driver.rb, line 68 68: def report_class_stuff(namespaces) 69: if namespaces.size == 1 70: klass = @ri_reader.get_class(namespaces[0]) 71: @display.display_class_info(klass, @ri_reader) 72: else 73: # entries = namespaces.find_all {|m| m.full_name == requested_class_name} 74: # if entries.size == 1 75: # klass = @ri_reader.get_class(entries[0]) 76: # @display.display_class_info(klass, @ri_reader) 77: # else 78: @display.display_class_list(namespaces) 79: # end 80: end 81: end
If the list of matching methods contains exactly one entry, or if it contains an entry that exactly matches the requested method, then display that entry, otherwise display the list of matching method names
# File ri/ri_driver.rb, line 51 51: def report_method_stuff(requested_method_name, methods) 52: if methods.size == 1 53: method = @ri_reader.get_method(methods[0]) 54: @display.display_method_info(method) 55: else 56: entries = methods.find_all {|m| m.name == requested_method_name} 57: if entries.size == 1 58: method = @ri_reader.get_method(entries[0]) 59: @display.display_method_info(method) 60: else 61: @display.display_method_list(methods) 62: end 63: end 64: end
Couldn‘t find documentation in paths, so tell the user what to do
# File ri/ri_driver.rb, line 35 35: def report_missing_documentation(paths) 36: STDERR.puts "No ri documentation found in:" 37: paths.each do |d| 38: STDERR.puts " #{d}" 39: end 40: STDERR.puts "\nWas rdoc run to create documentation?\n\n" 41: RDoc::usage("Installing Documentation") 42: end