summaryrefslogtreecommitdiff
path: root/lib/rdoc/generator/ri.rb
blob: ad9932a02a41c4017bc7b83fd7948c32ccb42d42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require 'rdoc/generator'
require 'rdoc/ri'

##
# Generates ri data files

class RDoc::Generator::RI

  RDoc::RDoc.add_generator self

  def self.for options
    new options
  end

  ##
  # Set up a new ri generator

  def initialize options #:not-new:
    @options     = options
    @store       = RDoc::RI::Store.new '.'
    @old_siginfo = nil
    @current     = nil
  end

  ##
  # Build the initial indices and output objects based on an array of TopLevel
  # objects containing the extracted information.

  def generate top_levels
    install_siginfo_handler

    RDoc::TopLevel.all_classes_and_modules.each do |klass|
      @current = "#{klass.class}: #{klass.full_name}"

      @store.save_class klass

      klass.each_method do |method|
        @current = "#{method.class}: #{method.full_name}"
        @store.save_method klass, method
      end

      klass.each_attribute do |attribute|
        @store.save_method klass, attribute
      end
    end

    @current = 'saving cache'

    @store.save_cache

  ensure
    @current = nil

    remove_siginfo_handler
  end

  ##
  # Installs a siginfo handler that prints the current filename.

  def install_siginfo_handler
    return unless Signal.list.key? 'INFO'

    @old_siginfo = trap 'INFO' do
      puts @current if @current
    end
  end

  ##
  # Removes a siginfo handler and replaces the previous

  def remove_siginfo_handler
    return unless Signal.list.key? 'INFO'

    handler = @old_siginfo || 'DEFAULT'

    trap 'INFO', handler
  end

end