~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to lib/rdoc/ri/ri_descriptions.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'yaml'
 
2
require 'rdoc/markup/simple_markup/fragments'
 
3
 
 
4
# Descriptions are created by RDoc (in ri_generator) and
 
5
# written out in serialized form into the documentation
 
6
# tree. ri then reads these to generate the documentation
 
7
 
 
8
module RI
 
9
  class NamedThing
 
10
    attr_reader :name
 
11
    def initialize(name)
 
12
      @name = name
 
13
    end
 
14
    def <=>(other)
 
15
      @name <=> other.name
 
16
    end
 
17
 
 
18
    def hash
 
19
      @name.hash
 
20
    end
 
21
 
 
22
    def eql?(other)
 
23
      @name.eql?(other)
 
24
    end
 
25
  end
 
26
 
 
27
#  Alias          = Struct.new(:old_name, :new_name)
 
28
 
 
29
  class AliasName < NamedThing
 
30
  end
 
31
 
 
32
  class Attribute < NamedThing
 
33
    attr_reader :rw, :comment
 
34
    def initialize(name, rw, comment)
 
35
      super(name)
 
36
      @rw = rw
 
37
      @comment = comment
 
38
    end
 
39
  end
 
40
 
 
41
  class Constant < NamedThing
 
42
    attr_reader :value, :comment
 
43
    def initialize(name, value, comment)
 
44
      super(name)
 
45
      @value = value
 
46
      @comment = comment
 
47
    end
 
48
  end
 
49
 
 
50
  class IncludedModule < NamedThing
 
51
  end
 
52
 
 
53
 
 
54
  class MethodSummary < NamedThing
 
55
    def initialize(name="")
 
56
      super
 
57
    end
 
58
  end
 
59
 
 
60
 
 
61
 
 
62
  class Description
 
63
    attr_accessor :name
 
64
    attr_accessor :full_name
 
65
    attr_accessor :comment
 
66
 
 
67
    def serialize
 
68
      self.to_yaml
 
69
    end
 
70
 
 
71
    def Description.deserialize(from)
 
72
      YAML.load(from)
 
73
    end
 
74
 
 
75
    def <=>(other)
 
76
      @name <=> other.name
 
77
    end
 
78
  end
 
79
  
 
80
  class ModuleDescription < Description
 
81
    
 
82
    attr_accessor :class_methods
 
83
    attr_accessor :instance_methods
 
84
    attr_accessor :attributes
 
85
    attr_accessor :constants
 
86
    attr_accessor :includes
 
87
 
 
88
    # merge in another class desscription into this one
 
89
    def merge_in(old)
 
90
      merge(@class_methods, old.class_methods)
 
91
      merge(@instance_methods, old.instance_methods)
 
92
      merge(@attributes, old.attributes)
 
93
      merge(@constants, old.constants)
 
94
      merge(@includes, old.includes)
 
95
      if @comment.nil? || @comment.empty?
 
96
        @comment = old.comment
 
97
      else
 
98
        unless old.comment.nil? or old.comment.empty? then
 
99
          @comment << SM::Flow::RULE.new
 
100
          @comment.concat old.comment
 
101
        end
 
102
      end
 
103
    end
 
104
 
 
105
    def display_name
 
106
      "Module"
 
107
    end
 
108
 
 
109
    # the 'ClassDescription' subclass overrides this
 
110
    # to format up the name of a parent
 
111
    def superclass_string
 
112
      nil
 
113
    end
 
114
 
 
115
    private
 
116
 
 
117
    def merge(into, from)
 
118
      names = {}
 
119
      into.each {|i| names[i.name] = i }
 
120
      from.each {|i| names[i.name] = i }
 
121
      into.replace(names.keys.sort.map {|n| names[n]})
 
122
    end
 
123
  end
 
124
  
 
125
  class ClassDescription < ModuleDescription
 
126
    attr_accessor :superclass
 
127
 
 
128
    def display_name
 
129
      "Class"
 
130
    end
 
131
 
 
132
    def superclass_string
 
133
      if @superclass && @superclass != "Object"
 
134
        @superclass
 
135
      else
 
136
        nil
 
137
      end
 
138
    end
 
139
  end
 
140
 
 
141
 
 
142
  class MethodDescription < Description
 
143
    
 
144
    attr_accessor :is_class_method
 
145
    attr_accessor :visibility
 
146
    attr_accessor :block_params
 
147
    attr_accessor :is_singleton
 
148
    attr_accessor :aliases
 
149
    attr_accessor :is_alias_for
 
150
    attr_accessor :params
 
151
 
 
152
  end
 
153
  
 
154
end