gitlab-rdoc 6.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.rdoc +220 -0
  3. data/CVE-2013-0256.rdoc +49 -0
  4. data/ExampleMarkdown.md +37 -0
  5. data/ExampleRDoc.rdoc +208 -0
  6. data/Gemfile +12 -0
  7. data/History.rdoc +1666 -0
  8. data/LEGAL.rdoc +50 -0
  9. data/LICENSE.rdoc +57 -0
  10. data/README.rdoc +133 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +101 -0
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/exe/rdoc +44 -0
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +112 -0
  19. data/lib/rdoc/anon_class.rb +11 -0
  20. data/lib/rdoc/any_method.rb +361 -0
  21. data/lib/rdoc/attr.rb +176 -0
  22. data/lib/rdoc/class_module.rb +802 -0
  23. data/lib/rdoc/code_object.rb +421 -0
  24. data/lib/rdoc/code_objects.rb +6 -0
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +187 -0
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +1266 -0
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +136 -0
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +42 -0
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +790 -0
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +160 -0
  37. data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  38. data/lib/rdoc/generator/pot/po.rb +84 -0
  39. data/lib/rdoc/generator/pot/po_entry.rb +141 -0
  40. data/lib/rdoc/generator/pot.rb +98 -0
  41. data/lib/rdoc/generator/ri.rb +31 -0
  42. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  44. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  57. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  58. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  59. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  60. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  72. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  73. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  74. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  75. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  76. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  77. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  78. data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  79. data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  80. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  81. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  82. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  83. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  84. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  85. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  86. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  87. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  88. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  89. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  90. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  91. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  92. data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -0
  93. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +84 -0
  94. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  95. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  96. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  97. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  98. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  99. data/lib/rdoc/generator/template/json_index/.document +1 -0
  100. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  101. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  102. data/lib/rdoc/generator.rb +51 -0
  103. data/lib/rdoc/ghost_method.rb +7 -0
  104. data/lib/rdoc/i18n/locale.rb +102 -0
  105. data/lib/rdoc/i18n/text.rb +126 -0
  106. data/lib/rdoc/i18n.rb +10 -0
  107. data/lib/rdoc/include.rb +10 -0
  108. data/lib/rdoc/known_classes.rb +73 -0
  109. data/lib/rdoc/markdown/entities.rb +2132 -0
  110. data/lib/rdoc/markdown/literals.kpeg +23 -0
  111. data/lib/rdoc/markdown/literals.rb +417 -0
  112. data/lib/rdoc/markdown.kpeg +1237 -0
  113. data/lib/rdoc/markdown.rb +16685 -0
  114. data/lib/rdoc/markup/attr_changer.rb +23 -0
  115. data/lib/rdoc/markup/attr_span.rb +36 -0
  116. data/lib/rdoc/markup/attribute_manager.rb +409 -0
  117. data/lib/rdoc/markup/attributes.rb +71 -0
  118. data/lib/rdoc/markup/blank_line.rb +28 -0
  119. data/lib/rdoc/markup/block_quote.rb +15 -0
  120. data/lib/rdoc/markup/document.rb +165 -0
  121. data/lib/rdoc/markup/formatter.rb +266 -0
  122. data/lib/rdoc/markup/hard_break.rb +32 -0
  123. data/lib/rdoc/markup/heading.rb +79 -0
  124. data/lib/rdoc/markup/include.rb +43 -0
  125. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  126. data/lib/rdoc/markup/list.rb +102 -0
  127. data/lib/rdoc/markup/list_item.rb +100 -0
  128. data/lib/rdoc/markup/paragraph.rb +29 -0
  129. data/lib/rdoc/markup/parser.rb +575 -0
  130. data/lib/rdoc/markup/pre_process.rb +296 -0
  131. data/lib/rdoc/markup/raw.rb +70 -0
  132. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  133. data/lib/rdoc/markup/rule.rb +21 -0
  134. data/lib/rdoc/markup/table.rb +47 -0
  135. data/lib/rdoc/markup/to_ansi.rb +94 -0
  136. data/lib/rdoc/markup/to_bs.rb +77 -0
  137. data/lib/rdoc/markup/to_html.rb +444 -0
  138. data/lib/rdoc/markup/to_html_crossref.rb +176 -0
  139. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  140. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  141. data/lib/rdoc/markup/to_label.rb +75 -0
  142. data/lib/rdoc/markup/to_markdown.rb +192 -0
  143. data/lib/rdoc/markup/to_rdoc.rb +362 -0
  144. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  145. data/lib/rdoc/markup/to_test.rb +70 -0
  146. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  147. data/lib/rdoc/markup/verbatim.rb +84 -0
  148. data/lib/rdoc/markup.rb +867 -0
  149. data/lib/rdoc/meta_method.rb +7 -0
  150. data/lib/rdoc/method_attr.rb +419 -0
  151. data/lib/rdoc/mixin.rb +121 -0
  152. data/lib/rdoc/normal_class.rb +93 -0
  153. data/lib/rdoc/normal_module.rb +74 -0
  154. data/lib/rdoc/options.rb +1285 -0
  155. data/lib/rdoc/parser/c.rb +1225 -0
  156. data/lib/rdoc/parser/changelog.rb +335 -0
  157. data/lib/rdoc/parser/markdown.rb +24 -0
  158. data/lib/rdoc/parser/rd.rb +23 -0
  159. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  160. data/lib/rdoc/parser/ruby.rb +2327 -0
  161. data/lib/rdoc/parser/ruby_tools.rb +167 -0
  162. data/lib/rdoc/parser/simple.rb +61 -0
  163. data/lib/rdoc/parser/text.rb +12 -0
  164. data/lib/rdoc/parser.rb +277 -0
  165. data/lib/rdoc/rd/block_parser.rb +1056 -0
  166. data/lib/rdoc/rd/block_parser.ry +639 -0
  167. data/lib/rdoc/rd/inline.rb +72 -0
  168. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  169. data/lib/rdoc/rd/inline_parser.ry +593 -0
  170. data/lib/rdoc/rd.rb +100 -0
  171. data/lib/rdoc/rdoc.rb +579 -0
  172. data/lib/rdoc/require.rb +52 -0
  173. data/lib/rdoc/ri/driver.rb +1572 -0
  174. data/lib/rdoc/ri/formatter.rb +6 -0
  175. data/lib/rdoc/ri/paths.rb +171 -0
  176. data/lib/rdoc/ri/store.rb +7 -0
  177. data/lib/rdoc/ri/task.rb +71 -0
  178. data/lib/rdoc/ri.rb +21 -0
  179. data/lib/rdoc/rubygems_hook.rb +246 -0
  180. data/lib/rdoc/servlet.rb +451 -0
  181. data/lib/rdoc/single_class.rb +26 -0
  182. data/lib/rdoc/stats/normal.rb +58 -0
  183. data/lib/rdoc/stats/quiet.rb +60 -0
  184. data/lib/rdoc/stats/verbose.rb +46 -0
  185. data/lib/rdoc/stats.rb +462 -0
  186. data/lib/rdoc/store.rb +979 -0
  187. data/lib/rdoc/task.rb +329 -0
  188. data/lib/rdoc/text.rb +304 -0
  189. data/lib/rdoc/token_stream.rb +119 -0
  190. data/lib/rdoc/tom_doc.rb +263 -0
  191. data/lib/rdoc/top_level.rb +289 -0
  192. data/lib/rdoc/version.rb +8 -0
  193. data/lib/rdoc.rb +201 -0
  194. data/man/ri.1 +247 -0
  195. data/rdoc.gemspec +249 -0
  196. metadata +279 -0
data/lib/rdoc/attr.rb ADDED
@@ -0,0 +1,176 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # An attribute created by \#attr, \#attr_reader, \#attr_writer or
4
+ # \#attr_accessor
5
+
6
+ class RDoc::Attr < RDoc::MethodAttr
7
+
8
+ ##
9
+ # 3::
10
+ # RDoc 4
11
+ # Added parent name and class
12
+ # Added section title
13
+
14
+ MARSHAL_VERSION = 3 # :nodoc:
15
+
16
+ ##
17
+ # Is the attribute readable ('R'), writable ('W') or both ('RW')?
18
+
19
+ attr_accessor :rw
20
+
21
+ ##
22
+ # Creates a new Attr with body +text+, +name+, read/write status +rw+ and
23
+ # +comment+. +singleton+ marks this as a class attribute.
24
+
25
+ def initialize(text, name, rw, comment, singleton = false)
26
+ super text, name
27
+
28
+ @rw = rw
29
+ @singleton = singleton
30
+ self.comment = comment
31
+ end
32
+
33
+ ##
34
+ # Attributes are equal when their names, singleton and rw are identical
35
+
36
+ def == other
37
+ self.class == other.class and
38
+ self.name == other.name and
39
+ self.rw == other.rw and
40
+ self.singleton == other.singleton
41
+ end
42
+
43
+ ##
44
+ # Add +an_alias+ as an attribute in +context+.
45
+
46
+ def add_alias(an_alias, context)
47
+ new_attr = self.class.new(self.text, an_alias.new_name, self.rw,
48
+ self.comment, self.singleton)
49
+
50
+ new_attr.record_location an_alias.file
51
+ new_attr.visibility = self.visibility
52
+ new_attr.is_alias_for = self
53
+ @aliases << new_attr
54
+ context.add_attribute new_attr
55
+ new_attr
56
+ end
57
+
58
+ ##
59
+ # The #aref prefix for attributes
60
+
61
+ def aref_prefix
62
+ 'attribute'
63
+ end
64
+
65
+ ##
66
+ # Attributes never call super. See RDoc::AnyMethod#calls_super
67
+ #
68
+ # An RDoc::Attr can show up in the method list in some situations (see
69
+ # Gem::ConfigFile)
70
+
71
+ def calls_super # :nodoc:
72
+ false
73
+ end
74
+
75
+ ##
76
+ # Returns attr_reader, attr_writer or attr_accessor as appropriate.
77
+
78
+ def definition
79
+ case @rw
80
+ when 'RW' then 'attr_accessor'
81
+ when 'R' then 'attr_reader'
82
+ when 'W' then 'attr_writer'
83
+ end
84
+ end
85
+
86
+ def inspect # :nodoc:
87
+ alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
88
+ visibility = self.visibility
89
+ visibility = "forced #{visibility}" if force_documentation
90
+ "#<%s:0x%x %s %s (%s)%s>" % [
91
+ self.class, object_id,
92
+ full_name,
93
+ rw,
94
+ visibility,
95
+ alias_for,
96
+ ]
97
+ end
98
+
99
+ ##
100
+ # Dumps this Attr for use by ri. See also #marshal_load
101
+
102
+ def marshal_dump
103
+ [ MARSHAL_VERSION,
104
+ @name,
105
+ full_name,
106
+ @rw,
107
+ @visibility,
108
+ parse(@comment),
109
+ singleton,
110
+ @file.relative_name,
111
+ @parent.full_name,
112
+ @parent.class,
113
+ @section.title
114
+ ]
115
+ end
116
+
117
+ ##
118
+ # Loads this Attr from +array+. For a loaded Attr the following
119
+ # methods will return cached values:
120
+ #
121
+ # * #full_name
122
+ # * #parent_name
123
+
124
+ def marshal_load array
125
+ initialize_visibility
126
+
127
+ @aliases = []
128
+ @parent = nil
129
+ @parent_name = nil
130
+ @parent_class = nil
131
+ @section = nil
132
+ @file = nil
133
+
134
+ version = array[0]
135
+ @name = array[1]
136
+ @full_name = array[2]
137
+ @rw = array[3]
138
+ @visibility = array[4]
139
+ @comment = array[5]
140
+ @singleton = array[6] || false # MARSHAL_VERSION == 0
141
+ # 7 handled below
142
+ @parent_name = array[8]
143
+ @parent_class = array[9]
144
+ @section_title = array[10]
145
+
146
+ @file = RDoc::TopLevel.new array[7] if version > 1
147
+
148
+ @parent_name ||= @full_name.split('#', 2).first
149
+ end
150
+
151
+ def pretty_print q # :nodoc:
152
+ q.group 2, "[#{self.class.name} #{full_name} #{rw} #{visibility}", "]" do
153
+ unless comment.empty? then
154
+ q.breakable
155
+ q.text "comment:"
156
+ q.breakable
157
+ q.pp @comment
158
+ end
159
+ end
160
+ end
161
+
162
+ def to_s # :nodoc:
163
+ "#{definition} #{name} in: #{parent}"
164
+ end
165
+
166
+ ##
167
+ # Attributes do not have token streams.
168
+ #
169
+ # An RDoc::Attr can show up in the method list in some situations (see
170
+ # Gem::ConfigFile)
171
+
172
+ def token_stream # :nodoc:
173
+ end
174
+
175
+ end
176
+
@@ -0,0 +1,802 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # ClassModule is the base class for objects representing either a class or a
4
+ # module.
5
+
6
+ class RDoc::ClassModule < RDoc::Context
7
+
8
+ ##
9
+ # 1::
10
+ # RDoc 3.7
11
+ # * Added visibility, singleton and file to attributes
12
+ # * Added file to constants
13
+ # * Added file to includes
14
+ # * Added file to methods
15
+ # 2::
16
+ # RDoc 3.13
17
+ # * Added extends
18
+ # 3::
19
+ # RDoc 4.0
20
+ # * Added sections
21
+ # * Added in_files
22
+ # * Added parent name
23
+ # * Complete Constant dump
24
+
25
+ MARSHAL_VERSION = 3 # :nodoc:
26
+
27
+ ##
28
+ # Constants that are aliases for this class or module
29
+
30
+ attr_accessor :constant_aliases
31
+
32
+ ##
33
+ # Comment and the location it came from. Use #add_comment to add comments
34
+
35
+ attr_accessor :comment_location
36
+
37
+ attr_accessor :diagram # :nodoc:
38
+
39
+ ##
40
+ # Class or module this constant is an alias for
41
+
42
+ attr_accessor :is_alias_for
43
+
44
+ ##
45
+ # Return a RDoc::ClassModule of class +class_type+ that is a copy
46
+ # of module +module+. Used to promote modules to classes.
47
+ #--
48
+ # TODO move to RDoc::NormalClass (I think)
49
+
50
+ def self.from_module class_type, mod
51
+ klass = class_type.new mod.name
52
+
53
+ mod.comment_location.each do |comment, location|
54
+ klass.add_comment comment, location
55
+ end
56
+
57
+ klass.parent = mod.parent
58
+ klass.section = mod.section
59
+ klass.viewer = mod.viewer
60
+
61
+ klass.attributes.concat mod.attributes
62
+ klass.method_list.concat mod.method_list
63
+ klass.aliases.concat mod.aliases
64
+ klass.external_aliases.concat mod.external_aliases
65
+ klass.constants.concat mod.constants
66
+ klass.includes.concat mod.includes
67
+ klass.extends.concat mod.extends
68
+
69
+ klass.methods_hash.update mod.methods_hash
70
+ klass.constants_hash.update mod.constants_hash
71
+
72
+ klass.current_section = mod.current_section
73
+ klass.in_files.concat mod.in_files
74
+ klass.sections.concat mod.sections
75
+ klass.unmatched_alias_lists = mod.unmatched_alias_lists
76
+ klass.current_section = mod.current_section
77
+ klass.visibility = mod.visibility
78
+
79
+ klass.classes_hash.update mod.classes_hash
80
+ klass.modules_hash.update mod.modules_hash
81
+ klass.metadata.update mod.metadata
82
+
83
+ klass.document_self = mod.received_nodoc ? nil : mod.document_self
84
+ klass.document_children = mod.document_children
85
+ klass.force_documentation = mod.force_documentation
86
+ klass.done_documenting = mod.done_documenting
87
+
88
+ # update the parent of all children
89
+
90
+ (klass.attributes +
91
+ klass.method_list +
92
+ klass.aliases +
93
+ klass.external_aliases +
94
+ klass.constants +
95
+ klass.includes +
96
+ klass.extends +
97
+ klass.classes +
98
+ klass.modules).each do |obj|
99
+ obj.parent = klass
100
+ obj.full_name = nil
101
+ end
102
+
103
+ klass
104
+ end
105
+
106
+ ##
107
+ # Creates a new ClassModule with +name+ with optional +superclass+
108
+ #
109
+ # This is a constructor for subclasses, and must never be called directly.
110
+
111
+ def initialize(name, superclass = nil)
112
+ @constant_aliases = []
113
+ @diagram = nil
114
+ @is_alias_for = nil
115
+ @name = name
116
+ @superclass = superclass
117
+ @comment_location = [] # [[comment, location]]
118
+
119
+ super()
120
+ end
121
+
122
+ ##
123
+ # Adds +comment+ to this ClassModule's list of comments at +location+. This
124
+ # method is preferred over #comment= since it allows ri data to be updated
125
+ # across multiple runs.
126
+
127
+ def add_comment comment, location
128
+ return unless document_self
129
+
130
+ original = comment
131
+
132
+ comment = case comment
133
+ when RDoc::Comment then
134
+ comment.normalize
135
+ else
136
+ normalize_comment comment
137
+ end
138
+
139
+ if location.parser == RDoc::Parser::C
140
+ @comment_location.delete_if { |(_, l)| l == location }
141
+ end
142
+
143
+ @comment_location << [comment, location]
144
+
145
+ self.comment = original
146
+ end
147
+
148
+ def add_things my_things, other_things # :nodoc:
149
+ other_things.each do |group, things|
150
+ my_things[group].each { |thing| yield false, thing } if
151
+ my_things.include? group
152
+
153
+ things.each do |thing|
154
+ yield true, thing
155
+ end
156
+ end
157
+ end
158
+
159
+ ##
160
+ # Ancestors list for this ClassModule: the list of included modules
161
+ # (classes will add their superclass if any).
162
+ #
163
+ # Returns the included classes or modules, not the includes
164
+ # themselves. The returned values are either String or
165
+ # RDoc::NormalModule instances (see RDoc::Include#module).
166
+ #
167
+ # The values are returned in reverse order of their inclusion,
168
+ # which is the order suitable for searching methods/attributes
169
+ # in the ancestors. The superclass, if any, comes last.
170
+
171
+ def ancestors
172
+ includes.map { |i| i.module }.reverse
173
+ end
174
+
175
+ def aref_prefix # :nodoc:
176
+ raise NotImplementedError, "missing aref_prefix for #{self.class}"
177
+ end
178
+
179
+ ##
180
+ # HTML fragment reference for this module or class. See
181
+ # RDoc::NormalClass#aref and RDoc::NormalModule#aref
182
+
183
+ def aref
184
+ "#{aref_prefix}-#{full_name}"
185
+ end
186
+
187
+ ##
188
+ # Ancestors of this class or module only
189
+
190
+ alias direct_ancestors ancestors
191
+
192
+ ##
193
+ # Clears the comment. Used by the Ruby parser.
194
+
195
+ def clear_comment
196
+ @comment = ''
197
+ end
198
+
199
+ ##
200
+ # This method is deprecated, use #add_comment instead.
201
+ #
202
+ # Appends +comment+ to the current comment, but separated by a rule. Works
203
+ # more like <tt>+=</tt>.
204
+
205
+ def comment= comment # :nodoc:
206
+ comment = case comment
207
+ when RDoc::Comment then
208
+ comment.normalize
209
+ else
210
+ normalize_comment comment
211
+ end
212
+
213
+ comment = "#{@comment.to_s}\n---\n#{comment.to_s}" unless @comment.empty?
214
+
215
+ super comment
216
+ end
217
+
218
+ ##
219
+ # Prepares this ClassModule for use by a generator.
220
+ #
221
+ # See RDoc::Store#complete
222
+
223
+ def complete min_visibility
224
+ update_aliases
225
+ remove_nodoc_children
226
+ update_includes
227
+ remove_invisible min_visibility
228
+ end
229
+
230
+ ##
231
+ # Does this ClassModule or any of its methods have document_self set?
232
+
233
+ def document_self_or_methods
234
+ document_self || method_list.any?{ |m| m.document_self }
235
+ end
236
+
237
+ ##
238
+ # Does this class or module have a comment with content or is
239
+ # #received_nodoc true?
240
+
241
+ def documented?
242
+ return true if @received_nodoc
243
+ return false if @comment_location.empty?
244
+ @comment_location.any? { |comment, _| not comment.empty? }
245
+ end
246
+
247
+ ##
248
+ # Iterates the ancestors of this class or module for which an
249
+ # RDoc::ClassModule exists.
250
+
251
+ def each_ancestor # :yields: module
252
+ return enum_for __method__ unless block_given?
253
+
254
+ ancestors.each do |mod|
255
+ next if String === mod
256
+ next if self == mod
257
+ yield mod
258
+ end
259
+ end
260
+
261
+ ##
262
+ # Looks for a symbol in the #ancestors. See Context#find_local_symbol.
263
+
264
+ def find_ancestor_local_symbol symbol
265
+ each_ancestor do |m|
266
+ res = m.find_local_symbol(symbol)
267
+ return res if res
268
+ end
269
+
270
+ nil
271
+ end
272
+
273
+ ##
274
+ # Finds a class or module with +name+ in this namespace or its descendants
275
+
276
+ def find_class_named name
277
+ return self if full_name == name
278
+ return self if @name == name
279
+
280
+ @classes.values.find do |klass|
281
+ next if klass == self
282
+ klass.find_class_named name
283
+ end
284
+ end
285
+
286
+ ##
287
+ # Return the fully qualified name of this class or module
288
+
289
+ def full_name
290
+ @full_name ||= if RDoc::ClassModule === parent then
291
+ "#{parent.full_name}::#{@name}"
292
+ else
293
+ @name
294
+ end
295
+ end
296
+
297
+ ##
298
+ # TODO: filter included items by #display?
299
+
300
+ def marshal_dump # :nodoc:
301
+ attrs = attributes.sort.map do |attr|
302
+ next unless attr.display?
303
+ [ attr.name, attr.rw,
304
+ attr.visibility, attr.singleton, attr.file_name,
305
+ ]
306
+ end.compact
307
+
308
+ method_types = methods_by_type.map do |type, visibilities|
309
+ visibilities = visibilities.map do |visibility, methods|
310
+ method_names = methods.map do |method|
311
+ next unless method.display?
312
+ [method.name, method.file_name]
313
+ end.compact
314
+
315
+ [visibility, method_names.uniq]
316
+ end
317
+
318
+ [type, visibilities]
319
+ end
320
+
321
+ [ MARSHAL_VERSION,
322
+ @name,
323
+ full_name,
324
+ @superclass,
325
+ parse(@comment_location),
326
+ attrs,
327
+ constants.select { |constant| constant.display? },
328
+ includes.map do |incl|
329
+ next unless incl.display?
330
+ [incl.name, parse(incl.comment), incl.file_name]
331
+ end.compact,
332
+ method_types,
333
+ extends.map do |ext|
334
+ next unless ext.display?
335
+ [ext.name, parse(ext.comment), ext.file_name]
336
+ end.compact,
337
+ @sections.values,
338
+ @in_files.map do |tl|
339
+ tl.relative_name
340
+ end,
341
+ parent.full_name,
342
+ parent.class,
343
+ ]
344
+ end
345
+
346
+ def marshal_load array # :nodoc:
347
+ initialize_visibility
348
+ initialize_methods_etc
349
+ @current_section = nil
350
+ @document_self = true
351
+ @done_documenting = false
352
+ @parent = nil
353
+ @temporary_section = nil
354
+ @visibility = nil
355
+ @classes = {}
356
+ @modules = {}
357
+
358
+ @name = array[1]
359
+ @full_name = array[2]
360
+ @superclass = array[3]
361
+ @comment = array[4]
362
+
363
+ @comment_location = if RDoc::Markup::Document === @comment.parts.first then
364
+ @comment
365
+ else
366
+ RDoc::Markup::Document.new @comment
367
+ end
368
+
369
+ array[5].each do |name, rw, visibility, singleton, file|
370
+ singleton ||= false
371
+ visibility ||= :public
372
+
373
+ attr = RDoc::Attr.new nil, name, rw, nil, singleton
374
+
375
+ add_attribute attr
376
+ attr.visibility = visibility
377
+ attr.record_location RDoc::TopLevel.new file
378
+ end
379
+
380
+ array[6].each do |constant, comment, file|
381
+ case constant
382
+ when RDoc::Constant then
383
+ add_constant constant
384
+ else
385
+ constant = add_constant RDoc::Constant.new(constant, nil, comment)
386
+ constant.record_location RDoc::TopLevel.new file
387
+ end
388
+ end
389
+
390
+ array[7].each do |name, comment, file|
391
+ incl = add_include RDoc::Include.new(name, comment)
392
+ incl.record_location RDoc::TopLevel.new file
393
+ end
394
+
395
+ array[8].each do |type, visibilities|
396
+ visibilities.each do |visibility, methods|
397
+ @visibility = visibility
398
+
399
+ methods.each do |name, file|
400
+ method = RDoc::AnyMethod.new nil, name
401
+ method.singleton = true if type == 'class'
402
+ method.record_location RDoc::TopLevel.new file
403
+ add_method method
404
+ end
405
+ end
406
+ end
407
+
408
+ array[9].each do |name, comment, file|
409
+ ext = add_extend RDoc::Extend.new(name, comment)
410
+ ext.record_location RDoc::TopLevel.new file
411
+ end if array[9] # Support Marshal version 1
412
+
413
+ sections = (array[10] || []).map do |section|
414
+ [section.title, section]
415
+ end
416
+
417
+ @sections = Hash[*sections.flatten]
418
+ @current_section = add_section nil
419
+
420
+ @in_files = []
421
+
422
+ (array[11] || []).each do |filename|
423
+ record_location RDoc::TopLevel.new filename
424
+ end
425
+
426
+ @parent_name = array[12]
427
+ @parent_class = array[13]
428
+ end
429
+
430
+ ##
431
+ # Merges +class_module+ into this ClassModule.
432
+ #
433
+ # The data in +class_module+ is preferred over the receiver.
434
+
435
+ def merge class_module
436
+ @parent = class_module.parent
437
+ @parent_name = class_module.parent_name
438
+
439
+ other_document = parse class_module.comment_location
440
+
441
+ if other_document then
442
+ document = parse @comment_location
443
+
444
+ document = document.merge other_document
445
+
446
+ @comment = @comment_location = document
447
+ end
448
+
449
+ cm = class_module
450
+ other_files = cm.in_files
451
+
452
+ merge_collections attributes, cm.attributes, other_files do |add, attr|
453
+ if add then
454
+ add_attribute attr
455
+ else
456
+ @attributes.delete attr
457
+ @methods_hash.delete attr.pretty_name
458
+ end
459
+ end
460
+
461
+ merge_collections constants, cm.constants, other_files do |add, const|
462
+ if add then
463
+ add_constant const
464
+ else
465
+ @constants.delete const
466
+ @constants_hash.delete const.name
467
+ end
468
+ end
469
+
470
+ merge_collections includes, cm.includes, other_files do |add, incl|
471
+ if add then
472
+ add_include incl
473
+ else
474
+ @includes.delete incl
475
+ end
476
+ end
477
+
478
+ @includes.uniq! # clean up
479
+
480
+ merge_collections extends, cm.extends, other_files do |add, ext|
481
+ if add then
482
+ add_extend ext
483
+ else
484
+ @extends.delete ext
485
+ end
486
+ end
487
+
488
+ @extends.uniq! # clean up
489
+
490
+ merge_collections method_list, cm.method_list, other_files do |add, meth|
491
+ if add then
492
+ add_method meth
493
+ else
494
+ @method_list.delete meth
495
+ @methods_hash.delete meth.pretty_name
496
+ end
497
+ end
498
+
499
+ merge_sections cm
500
+
501
+ self
502
+ end
503
+
504
+ ##
505
+ # Merges collection +mine+ with +other+ preferring other. +other_files+ is
506
+ # used to help determine which items should be deleted.
507
+ #
508
+ # Yields whether the item should be added or removed (true or false) and the
509
+ # item to be added or removed.
510
+ #
511
+ # merge_collections things, other.things, other.in_files do |add, thing|
512
+ # if add then
513
+ # # add the thing
514
+ # else
515
+ # # remove the thing
516
+ # end
517
+ # end
518
+
519
+ def merge_collections mine, other, other_files, &block # :nodoc:
520
+ my_things = mine. group_by { |thing| thing.file }
521
+ other_things = other.group_by { |thing| thing.file }
522
+
523
+ remove_things my_things, other_files, &block
524
+ add_things my_things, other_things, &block
525
+ end
526
+
527
+ ##
528
+ # Merges the comments in this ClassModule with the comments in the other
529
+ # ClassModule +cm+.
530
+
531
+ def merge_sections cm # :nodoc:
532
+ my_sections = sections.group_by { |section| section.title }
533
+ other_sections = cm.sections.group_by { |section| section.title }
534
+
535
+ other_files = cm.in_files
536
+
537
+ remove_things my_sections, other_files do |_, section|
538
+ @sections.delete section.title
539
+ end
540
+
541
+ other_sections.each do |group, sections|
542
+ if my_sections.include? group
543
+ my_sections[group].each do |my_section|
544
+ other_section = cm.sections_hash[group]
545
+
546
+ my_comments = my_section.comments
547
+ other_comments = other_section.comments
548
+
549
+ other_files = other_section.in_files
550
+
551
+ merge_collections my_comments, other_comments, other_files do |add, comment|
552
+ if add then
553
+ my_section.add_comment comment
554
+ else
555
+ my_section.remove_comment comment
556
+ end
557
+ end
558
+ end
559
+ else
560
+ sections.each do |section|
561
+ add_section group, section.comments
562
+ end
563
+ end
564
+ end
565
+ end
566
+
567
+ ##
568
+ # Does this object represent a module?
569
+
570
+ def module?
571
+ false
572
+ end
573
+
574
+ ##
575
+ # Allows overriding the initial name.
576
+ #
577
+ # Used for modules and classes that are constant aliases.
578
+
579
+ def name= new_name
580
+ @name = new_name
581
+ end
582
+
583
+ ##
584
+ # Parses +comment_location+ into an RDoc::Markup::Document composed of
585
+ # multiple RDoc::Markup::Documents with their file set.
586
+
587
+ def parse comment_location
588
+ case comment_location
589
+ when String then
590
+ super
591
+ when Array then
592
+ docs = comment_location.map do |comment, location|
593
+ doc = super comment
594
+ doc.file = location
595
+ doc
596
+ end
597
+
598
+ RDoc::Markup::Document.new(*docs)
599
+ when RDoc::Comment then
600
+ doc = super comment_location.text, comment_location.format
601
+ doc.file = comment_location.location
602
+ doc
603
+ when RDoc::Markup::Document then
604
+ return comment_location
605
+ else
606
+ raise ArgumentError, "unknown comment class #{comment_location.class}"
607
+ end
608
+ end
609
+
610
+ ##
611
+ # Path to this class or module for use with HTML generator output.
612
+
613
+ def path
614
+ http_url @store.rdoc.generator.class_dir
615
+ end
616
+
617
+ ##
618
+ # Name to use to generate the url:
619
+ # modules and classes that are aliases for another
620
+ # module or class return the name of the latter.
621
+
622
+ def name_for_path
623
+ is_alias_for ? is_alias_for.full_name : full_name
624
+ end
625
+
626
+ ##
627
+ # Returns the classes and modules that are not constants
628
+ # aliasing another class or module. For use by formatters
629
+ # only (caches its result).
630
+
631
+ def non_aliases
632
+ @non_aliases ||= classes_and_modules.reject { |cm| cm.is_alias_for }
633
+ end
634
+
635
+ ##
636
+ # Updates the child modules or classes of class/module +parent+ by
637
+ # deleting the ones that have been removed from the documentation.
638
+ #
639
+ # +parent_hash+ is either <tt>parent.modules_hash</tt> or
640
+ # <tt>parent.classes_hash</tt> and +all_hash+ is ::all_modules_hash or
641
+ # ::all_classes_hash.
642
+
643
+ def remove_nodoc_children
644
+ prefix = self.full_name + '::'
645
+
646
+ modules_hash.each_key do |name|
647
+ full_name = prefix + name
648
+ modules_hash.delete name unless @store.modules_hash[full_name]
649
+ end
650
+
651
+ classes_hash.each_key do |name|
652
+ full_name = prefix + name
653
+ classes_hash.delete name unless @store.classes_hash[full_name]
654
+ end
655
+ end
656
+
657
+ def remove_things my_things, other_files # :nodoc:
658
+ my_things.delete_if do |file, things|
659
+ next false unless other_files.include? file
660
+
661
+ things.each do |thing|
662
+ yield false, thing
663
+ end
664
+
665
+ true
666
+ end
667
+ end
668
+
669
+ ##
670
+ # Search record used by RDoc::Generator::JsonIndex
671
+
672
+ def search_record
673
+ [
674
+ name,
675
+ full_name,
676
+ full_name,
677
+ '',
678
+ path,
679
+ '',
680
+ snippet(@comment_location),
681
+ ]
682
+ end
683
+
684
+ ##
685
+ # Sets the store for this class or module and its contained code objects.
686
+
687
+ def store= store
688
+ super
689
+
690
+ @attributes .each do |attr| attr.store = store end
691
+ @constants .each do |const| const.store = store end
692
+ @includes .each do |incl| incl.store = store end
693
+ @extends .each do |ext| ext.store = store end
694
+ @method_list.each do |meth| meth.store = store end
695
+ end
696
+
697
+ ##
698
+ # Get the superclass of this class. Attempts to retrieve the superclass
699
+ # object, returns the name if it is not known.
700
+
701
+ def superclass
702
+ @store.find_class_named(@superclass) || @superclass
703
+ end
704
+
705
+ ##
706
+ # Set the superclass of this class to +superclass+
707
+
708
+ def superclass=(superclass)
709
+ raise NoMethodError, "#{full_name} is a module" if module?
710
+ @superclass = superclass
711
+ end
712
+
713
+ def to_s # :nodoc:
714
+ if is_alias_for then
715
+ "#{self.class.name} #{self.full_name} -> #{is_alias_for}"
716
+ else
717
+ super
718
+ end
719
+ end
720
+
721
+ ##
722
+ # 'module' or 'class'
723
+
724
+ def type
725
+ module? ? 'module' : 'class'
726
+ end
727
+
728
+ ##
729
+ # Updates the child modules & classes by replacing the ones that are
730
+ # aliases through a constant.
731
+ #
732
+ # The aliased module/class is replaced in the children and in
733
+ # RDoc::Store#modules_hash or RDoc::Store#classes_hash
734
+ # by a copy that has <tt>RDoc::ClassModule#is_alias_for</tt> set to
735
+ # the aliased module/class, and this copy is added to <tt>#aliases</tt>
736
+ # of the aliased module/class.
737
+ #
738
+ # Formatters can use the #non_aliases method to retrieve children that
739
+ # are not aliases, for instance to list the namespace content, since
740
+ # the aliased modules are included in the constants of the class/module,
741
+ # that are listed separately.
742
+
743
+ def update_aliases
744
+ constants.each do |const|
745
+ next unless cm = const.is_alias_for
746
+ cm_alias = cm.dup
747
+ cm_alias.name = const.name
748
+
749
+ # Don't move top-level aliases under Object, they look ugly there
750
+ unless RDoc::TopLevel === cm_alias.parent then
751
+ cm_alias.parent = self
752
+ cm_alias.full_name = nil # force update for new parent
753
+ end
754
+
755
+ cm_alias.aliases.clear
756
+ cm_alias.is_alias_for = cm
757
+
758
+ if cm.module? then
759
+ @store.modules_hash[cm_alias.full_name] = cm_alias
760
+ modules_hash[const.name] = cm_alias
761
+ else
762
+ @store.classes_hash[cm_alias.full_name] = cm_alias
763
+ classes_hash[const.name] = cm_alias
764
+ end
765
+
766
+ cm.aliases << cm_alias
767
+ end
768
+ end
769
+
770
+ ##
771
+ # Deletes from #includes those whose module has been removed from the
772
+ # documentation.
773
+ #--
774
+ # FIXME: includes are not reliably removed, see _possible_bug test case
775
+
776
+ def update_includes
777
+ includes.reject! do |include|
778
+ mod = include.module
779
+ !(String === mod) && @store.modules_hash[mod.full_name].nil?
780
+ end
781
+
782
+ includes.uniq!
783
+ end
784
+
785
+ ##
786
+ # Deletes from #extends those whose module has been removed from the
787
+ # documentation.
788
+ #--
789
+ # FIXME: like update_includes, extends are not reliably removed
790
+
791
+ def update_extends
792
+ extends.reject! do |ext|
793
+ mod = ext.module
794
+
795
+ !(String === mod) && @store.modules_hash[mod.full_name].nil?
796
+ end
797
+
798
+ extends.uniq!
799
+ end
800
+
801
+ end
802
+