Class: IHelp::IHelpDriver
Overview
Version of RiDriver that takes its options as parameter to #initialize.
Instance Method Summary collapse
-
#display_info(info) ⇒ Object
Display the info based on if it’s for a class or a method.
-
#get_class_info_str(namespaces) ⇒ Object
Get info for the class in the given namespaces.
-
#get_info_str(klass_name, method_name = nil, instance = false) ⇒ Object
Get info string from ri database for klass_name [method_name].
-
#get_method_info_str(requested_method_name, methods) ⇒ Object
Get info for the method in the given methods.
-
#initialize(args = []) ⇒ IHelpDriver
constructor
Create new IHelpDriver, with the given args passed to @options, which is a RI::Options.instance.
Constructor Details
#initialize(args = []) ⇒ IHelpDriver
Create new IHelpDriver, with the given args passed to @options, which is a RI::Options.instance
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/ihelp.rb', line 394 def initialize(args = []) = RI::Options.instance .parse(args) paths = (if RUBY_VERSION > "1.8.4" .doc_dir else .paths end) || RI::Paths::PATH if paths.empty? report_missing_documentation(paths) end @ri_reader = RI::RiReader.new(RI::RiCache.new(paths)) @display = .displayer end |
Instance Method Details
#display_info(info) ⇒ Object
Display the info based on if it’s for a class or a method. Using ri’s pager.
433 434 435 436 437 438 439 440 |
# File 'lib/ihelp.rb', line 433 def display_info(info) case [info.class] # only info.class doesn't work when [RI::ClassDescription] @display.display_class_info(info, @ri_reader) when [RI::MethodDescription] @display.display_method_info(info) end end |
#get_class_info_str(namespaces) ⇒ Object
Get info for the class in the given namespaces.
444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/ihelp.rb', line 444 def get_class_info_str(namespaces) return nil if namespaces.empty? klass = nil namespaces.find{|ns| begin klass = @ri_reader.get_class(ns) rescue TypeError nil end } klass end |
#get_info_str(klass_name, method_name = nil, instance = false) ⇒ Object
Get info string from ri database for klass_name [method_name]
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/ihelp.rb', line 412 def get_info_str(klass_name, method_name = nil, instance = false) is_class_method = (not instance) top_level_namespace = @ri_reader.top_level_namespace namespaces = klass_name.split(/::/).inject(top_level_namespace){ |ns, current_name| @ri_reader.lookup_namespace_in(current_name, ns) } return nil if namespaces.empty? if method_name.nil? get_class_info_str(namespaces) else methods = @ri_reader.find_methods( method_name, is_class_method, namespaces) return nil if methods.empty? get_method_info_str(method_name, methods) end end |
#get_method_info_str(requested_method_name, methods) ⇒ Object
Get info for the method in the given methods.
459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/ihelp.rb', line 459 def get_method_info_str(requested_method_name, methods) if methods.size == 1 @ri_reader.get_method(methods.first) else entries = methods.find_all {|m| m.name == requested_method_name} return nil if entries.empty? method = nil entries.find{|entry| method = @ri_reader.get_method(entry)} method end end |