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: path = @options.path 25: report_missing_documentation @options.raw_path if path.empty? 26: 27: @ri_reader = RI::RiReader.new(RI::RiCache.new(path)) 28: @display = @options.displayer 29: end
# File ri/ri_driver.rb, line 84 84: def get_info_for(arg) 85: desc = NameDescriptor.new(arg) 86: 87: namespaces = @ri_reader.top_level_namespace 88: 89: for class_name in desc.class_names 90: namespaces = @ri_reader.lookup_namespace_in(class_name, namespaces) 91: if namespaces.empty? 92: raise RiError.new("Nothing known about #{arg}") 93: end 94: end 95: 96: # at this point, if we have multiple possible namespaces, but one 97: # is an exact match for our requested class, prune down to just it 98: 99: full_class_name = desc.full_class_name 100: entries = namespaces.find_all {|m| m.full_name == full_class_name} 101: namespaces = entries if entries.size == 1 102: 103: if desc.method_name.nil? 104: report_class_stuff(namespaces) 105: else 106: methods = @ri_reader.find_methods(desc.method_name, 107: desc.is_class_method, 108: namespaces) 109: 110: if methods.empty? 111: raise RiError.new("Nothing known about #{arg}") 112: else 113: report_method_stuff(desc.method_name, methods) 114: end 115: end 116: end
# File ri/ri_driver.rb, line 120 120: def process_args 121: if @options.list_classes 122: classes = @ri_reader.full_class_names 123: @display.list_known_classes(classes) 124: elsif @options.list_names 125: names = @ri_reader.all_names 126: @display.list_known_names(names) 127: else 128: if ARGV.size.zero? 129: @display.display_usage 130: else 131: begin 132: ARGV.each do |arg| 133: get_info_for(arg) 134: end 135: rescue RiError => e 136: STDERR.puts(e.message) 137: exit(1) 138: end 139: end 140: end 141: end
# File ri/ri_driver.rb, line 66 66: def report_class_stuff(namespaces) 67: if namespaces.size == 1 68: klass = @ri_reader.get_class(namespaces[0]) 69: @display.display_class_info(klass, @ri_reader) 70: else 71: # entries = namespaces.find_all {|m| m.full_name == requested_class_name} 72: # if entries.size == 1 73: # klass = @ri_reader.get_class(entries[0]) 74: # @display.display_class_info(klass, @ri_reader) 75: # else 76: @display.display_class_list(namespaces) 77: # end 78: end 79: 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 49 49: def report_method_stuff(requested_method_name, methods) 50: if methods.size == 1 51: method = @ri_reader.get_method(methods[0]) 52: @display.display_method_info(method) 53: else 54: entries = methods.find_all {|m| m.name == requested_method_name} 55: if entries.size == 1 56: method = @ri_reader.get_method(entries[0]) 57: @display.display_method_info(method) 58: else 59: @display.display_method_list(methods) 60: end 61: end 62: end
Couldn‘t find documentation in path, so tell the user what to do
# File ri/ri_driver.rb, line 33 33: def report_missing_documentation(path) 34: STDERR.puts "No ri documentation found in:" 35: path.each do |d| 36: STDERR.puts " #{d}" 37: end 38: STDERR.puts "\nWas rdoc run to create documentation?\n\n" 39: RDoc::usage("Installing Documentation") 40: end