Class: RDoc::RI::Driver

Inherits:
Object show all
Defined in:
lib/coderunner/interactive_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.process_args(argv) ⇒ Object



540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
# File 'lib/coderunner/interactive_methods.rb', line 540

def self.process_args(argv)
  options = default_options

  opts = OptionParser.new do |opt|
    opt.program_name = File.basename $0
    opt.version = RDoc::VERSION
    opt.release = nil
    opt.summary_indent = ' ' * 4

    directories = [
      RDoc::RI::Paths::SYSDIR,
      RDoc::RI::Paths::SITEDIR,
      RDoc::RI::Paths::HOMEDIR
    ]

    if RDoc::RI::Paths::GEMDIRS then
      Gem.path.each do |dir|
        directories << "#{dir}/doc/*/ri"
      end
    end

    opt.banner = <<-EOT
Usage: #{opt.program_name} [options] [names...]

Where name can be:

Class | Class::method | Class#method | Class.method | method

All class names may be abbreviated to their minimum unambiguous form. If a name
is ambiguous, all valid options will be listed.

The form '.' method matches either class or instance methods, while #method
matches only instance and ::method matches only class methods.

For example:

  #{opt.program_name} Fil
  #{opt.program_name} File
  #{opt.program_name} File.new
  #{opt.program_name} zip

Note that shell quoting may be required for method names containing
punctuation:

  #{opt.program_name} 'Array.[]'
  #{opt.program_name} compact\\!

By default ri searches for documentation in the following directories:

  #{directories.join "\n    "}

Specifying the --system, --site, --home, --gems or --doc-dir options will
limit ri to searching only the specified directories.

Options may also be set in the 'RI' environment variable.
    EOT

    opt.separator nil
    opt.separator "Options:"
    opt.separator nil

    opt.on("--fmt=FORMAT", "--format=FORMAT", "-f",
           RDoc::RI::Formatter::FORMATTERS.keys,
           "Format to use when displaying output:",
           "   #{RDoc::RI::Formatter.list}",
           "Use 'bs' (backspace) with most pager",
           "programs. To use ANSI, either disable the",
           "pager or tell the pager to allow control",
           "characters.") do |value|
      options[:formatter] = RDoc::RI::Formatter.for value
    end

    opt.separator nil

    opt.on("--doc-dir=DIRNAME", "-d", Array,
           "List of directories from which to source",
           "documentation in addition to the standard",
           "directories.  May be repeated.") do |value|
      value.each do |dir|
        unless File.directory? dir then
          raise OptionParser::InvalidArgument, "#{dir} is not a directory"
        end

        options[:extra_doc_dirs] << File.expand_path(dir)
      end
    end

    opt.separator nil

    opt.on("--[no-]use-cache",
           "Whether or not to use ri's cache.",
           "True by default.") do |value|
      options[:use_cache] = value
    end

    opt.separator nil

    opt.on("--no-standard-docs",
           "Do not include documentation from",
           "the Ruby standard library, site_lib,",
           "installed gems, or ~/.rdoc.",
           "Equivalent to specifying",
           "the options --no-system, --no-site, --no-gems,",
           "and --no-home") do
      options[:use_system] = false
      options[:use_site] = false
      options[:use_gems] = false
      options[:use_home] = false
    end

    opt.separator nil

    opt.on("--[no-]system",
           "Include documentation from Ruby's standard",
           "library.  Defaults to true.") do |value|
      options[:use_system] = value
    end

    opt.separator nil

    opt.on("--[no-]site",
           "Include documentation from libraries",
           "installed in site_lib.",
           "Defaults to true.") do |value|
      options[:use_site] = value
    end

    opt.separator nil

    opt.on("--[no-]gems",
           "Include documentation from RubyGems.",
           "Defaults to true.") do |value|
      options[:use_gems] = value
    end

    opt.separator nil

    opt.on("--[no-]home",
           "Include documentation stored in ~/.rdoc.",
           "Defaults to true.") do |value|
      options[:use_home] = value
    end

    opt.separator nil

    opt.on("--list-doc-dirs",
           "List the directories from which ri will",
           "source documentation on stdout and exit.") do
      options[:list_doc_dirs] = true
    end

    opt.separator nil

    opt.on("--no-pager", "-T",
           "Send output directly to stdout,",
           "rather than to a pager.") do
      options[:use_stdout] = true
    end

    opt.on("--interactive", "-i",
           "This makes ri go into interactive mode.",
           "When ri is in interactive mode it will",
           "allow the user to disambiguate lists of",
           "methods in case multiple methods match",
           "against a method search string.  It also",
           "will allow the user to enter in a method",
           "name (with auto-completion, if readline",
           "is supported) when viewing a class.") do
      options[:interactive] = true
    end

    opt.separator nil

    opt.on("--width=WIDTH", "-w", OptionParser::DecimalInteger,
           "Set the width of the output.") do |value|
      options[:width] = value
    end
  end

  argv = ENV['RI'].to_s.split.concat argv

  opts.parse! argv

  options[:names] = argv

  options[:formatter] ||= RDoc::RI::Formatter.for('plain')
  options[:use_stdout] ||= !$stdout.tty?
  options[:use_stdout] ||= options[:interactive]
  options[:width] ||= 72

  options

rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
  puts opts
  puts
  puts e
#     exit 1
end

Instance Method Details

#runObject



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/coderunner/interactive_methods.rb', line 475

def run
  if(@list_doc_dirs)
    puts @doc_dirs.join("\n")
  elsif @names.empty? then
    @display.list_known_classes class_cache.keys.sort
  else
	
	@names.each do |name|
      if class_cache.key? name then
        method_map = display_class name
        if(@interactive)
          method_name = @display.get_class_method_choice(method_map)

          if(method_name != nil)
            method = lookup_method "#{name}#{method_name}", name
            display_method method
          end
        end
      elsif name =~ /::|\#|\./ then
        klass, = parse_name name

        orig_klass = klass
        orig_name = name

        loop do
          method = lookup_method name, klass

          break method if method

          ancestor = lookup_ancestor klass, orig_klass

          break unless ancestor

          name = name.sub klass, ancestor
          klass = ancestor
        end
			
# 					return unless method

        raise NotFoundError, orig_name unless method

        display_method method
      else
        methods = select_methods(/#{name}/)

        if methods.size == 0
        return  
				raise NotFoundError, name
        elsif methods.size == 1
          display_method methods[0]
        else
          if(@interactive)
            @display.display_method_list_choice methods
          else
            @display.display_method_list methods
          end
        end
      end
    end
  end
#   rescue NotFoundError => e
#     eputs e
# 		return
end