Class: IHelp::IHelpDriver

Inherits:
RiDriver
  • Object
show all
Defined in:
lib/ihelp.rb

Overview

Version of RiDriver that takes its options as parameter to #initialize.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = (ENV["RI"] || "").split) ⇒ IHelpDriver

Create new IHelpDriver, with the given args passed to @options, which is a RI::Options.instance



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/ihelp.rb', line 500

def initialize(args = (ENV["RI"] || "").split)
  @options = RI::Options.instance
  @options.parse(args)

  paths =  (if RUBY_VERSION > "1.8.4"
              @options.doc_dir
            else
              @options.paths
            end) || RI::Paths::PATH
  if paths.empty?
    report_missing_documentation(paths)
  end
  @ri_reader = RI::RiReader.new(RI::RiCache.new(paths))
  @display   = @options.displayer
end

Instance Attribute Details

#displayObject

Returns the value of attribute display.



495
496
497
# File 'lib/ihelp.rb', line 495

def display
  @display
end

#ri_readerObject

Returns the value of attribute ri_reader.



495
496
497
# File 'lib/ihelp.rb', line 495

def ri_reader
  @ri_reader
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.



539
540
541
542
543
544
545
546
# File 'lib/ihelp.rb', line 539

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, klass_name) ⇒ Object

Get info for the class in the given namespaces.



550
551
552
553
554
555
556
557
558
559
560
561
562
563
# File 'lib/ihelp.rb', line 550

def get_class_info_str(namespaces, klass_name)
  return nil if namespaces.empty?
  klass_name_last = klass_name.split("::").last
  klass = nil
  namespaces.find{|ns|
    begin
      ns.name == klass_name_last and
      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]



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/ihelp.rb', line 518

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, klass_name)
  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.



567
568
569
570
571
572
573
# File 'lib/ihelp.rb', line 567

def get_method_info_str(requested_method_name, methods)
  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