summaryrefslogtreecommitdiff
path: root/lib/rdoc/class_module.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-27 04:28:14 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-27 04:28:14 +0000
commit1c279a7d2753949c725754e1302f791b76358114 ()
tree36aa3bdde250e564445eba5f2e25fcb96bcb6cef /lib/rdoc/class_module.rb
parentc72f0daa877808e4fa5018b3191ca09d4b97c03d (diff)
* lib/rdoc*: Updated to RDoc 4.0 ()
* bin/rdoc: ditto * test/rdoc: ditto * NEWS: Updated with RDoc 4.0 information git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--lib/rdoc/class_module.rb267
1 files changed, 227 insertions, 40 deletions
@@ -1,5 +1,3 @@
-require 'rdoc/context'
-
##
# ClassModule is the base class for objects representing either a class or a
# module.
@@ -13,8 +11,17 @@ class RDoc::ClassModule < RDoc::Context
# * Added file to constants
# * Added file to includes
# * Added file to methods
-
- MARSHAL_VERSION = 1 # :nodoc:
##
# Constants that are aliases for this class or module
@@ -56,6 +63,7 @@ class RDoc::ClassModule < RDoc::Context
klass.external_aliases.concat mod.external_aliases
klass.constants.concat mod.constants
klass.includes.concat mod.includes
klass.methods_hash.update mod.methods_hash
klass.constants_hash.update mod.constants_hash
@@ -84,6 +92,7 @@ class RDoc::ClassModule < RDoc::Context
klass.external_aliases +
klass.constants +
klass.includes +
klass.classes +
klass.modules).each do |obj|
obj.parent = klass
@@ -115,16 +124,32 @@ class RDoc::ClassModule < RDoc::Context
# across multiple runs.
def add_comment comment, location
- return if comment.empty? or not document_self
original = comment
- comment = normalize_comment comment
@comment_location << [comment, location]
self.comment = original
end
##
# Ancestors list for this ClassModule: the list of included modules
# (classes will add their superclass if any).
@@ -142,6 +167,11 @@ class RDoc::ClassModule < RDoc::Context
end
##
# Clears the comment. Used by the ruby parser.
def clear_comment
@@ -155,9 +185,13 @@ class RDoc::ClassModule < RDoc::Context
# more like <tt>+=</tt>.
def comment= comment
- return if comment.empty?
- comment = normalize_comment comment
comment = "#{@comment}\n---\n#{comment}" unless @comment.empty?
super comment
@@ -166,7 +200,7 @@ class RDoc::ClassModule < RDoc::Context
##
# Prepares this ClassModule for use by a generator.
#
- # See RDoc::TopLevel::complete
def complete min_visibility
update_aliases
@@ -176,12 +210,22 @@ class RDoc::ClassModule < RDoc::Context
end
##
# Iterates the ancestors of this class or module for which an
# RDoc::ClassModule exists.
def each_ancestor # :yields: module
ancestors.each do |mod|
next if String === mod
yield mod
end
end
@@ -215,8 +259,8 @@ class RDoc::ClassModule < RDoc::Context
# Return the fully qualified name of this class or module
def full_name
- @full_name ||= if RDoc::ClassModule === @parent then
- "#{@parent.full_name}::#{@name}"
else
@name
end
@@ -250,13 +294,20 @@ class RDoc::ClassModule < RDoc::Context
@superclass,
parse(@comment_location),
attrs,
- constants.map do |const|
- [const.name, parse(const.comment), const.file_name]
- end,
includes.map do |incl|
[incl.name, parse(incl.comment), incl.file_name]
end,
method_types,
]
end
@@ -268,6 +319,8 @@ class RDoc::ClassModule < RDoc::Context
@parent = nil
@temporary_section = nil
@visibility = nil
@name = array[1]
@full_name = array[2]
@@ -291,9 +344,14 @@ class RDoc::ClassModule < RDoc::Context
attr.record_location RDoc::TopLevel.new file
end
- array[6].each do |name, comment, file|
- const = add_constant RDoc::Constant.new(name, nil, comment)
- const.record_location RDoc::TopLevel.new file
end
array[7].each do |name, comment, file|
@@ -313,6 +371,27 @@ class RDoc::ClassModule < RDoc::Context
end
end
end
end
##
@@ -321,6 +400,9 @@ class RDoc::ClassModule < RDoc::Context
# The data in +class_module+ is preferred over the receiver.
def merge class_module
other_document = parse class_module.comment_location
if other_document then
@@ -360,6 +442,18 @@ class RDoc::ClassModule < RDoc::Context
end
end
merge_collections method_list, cm.method_list, other_files do |add, meth|
if add then
add_method meth
@@ -369,6 +463,8 @@ class RDoc::ClassModule < RDoc::Context
end
end
self
end
@@ -391,22 +487,46 @@ class RDoc::ClassModule < RDoc::Context
my_things = mine. group_by { |thing| thing.file }
other_things = other.group_by { |thing| thing.file }
- my_things.delete_if do |file, things|
- next false unless other_files.include? file
- things.each do |thing|
- yield false, thing
- end
- true
end
- other_things.each do |file, things|
- my_things[file].each { |thing| yield false, thing } if
- my_things.include?(file)
- things.each do |thing|
- yield true, thing
end
end
end
@@ -438,11 +558,15 @@ class RDoc::ClassModule < RDoc::Context
when Array then
docs = comment_location.map do |comment, location|
doc = super comment
- doc.file = location.absolute_name
doc
end
RDoc::Markup::Document.new(*docs)
when RDoc::Markup::Document then
return comment_location
else
@@ -451,10 +575,10 @@ class RDoc::ClassModule < RDoc::Context
end
##
- # Path to this class or module
def path
- http_url RDoc::RDoc.current.generator.class_dir
end
##
@@ -488,21 +612,61 @@ class RDoc::ClassModule < RDoc::Context
modules_hash.each_key do |name|
full_name = prefix + name
- modules_hash.delete name unless RDoc::TopLevel.all_modules_hash[full_name]
end
classes_hash.each_key do |name|
full_name = prefix + name
- classes_hash.delete name unless RDoc::TopLevel.all_classes_hash[full_name]
end
end
##
# Get the superclass of this class. Attempts to retrieve the superclass
# object, returns the name if it is not known.
def superclass
- RDoc::TopLevel.find_class_named(@superclass) || @superclass
end
##
@@ -533,7 +697,7 @@ class RDoc::ClassModule < RDoc::Context
# aliases through a constant.
#
# The aliased module/class is replaced in the children and in
- # RDoc::TopLevel::all_modules_hash or RDoc::TopLevel::all_classes_hash
# by a copy that has <tt>RDoc::ClassModule#is_alias_for</tt> set to
# the aliased module/class, and this copy is added to <tt>#aliases</tt>
# of the aliased module/class.
@@ -548,16 +712,21 @@ class RDoc::ClassModule < RDoc::Context
next unless cm = const.is_alias_for
cm_alias = cm.dup
cm_alias.name = const.name
- cm_alias.parent = self
- cm_alias.full_name = nil # force update for new parent
cm_alias.aliases.clear
cm_alias.is_alias_for = cm
if cm.module? then
- RDoc::TopLevel.all_modules_hash[cm_alias.full_name] = cm_alias
modules_hash[const.name] = cm_alias
else
- RDoc::TopLevel.all_classes_hash[cm_alias.full_name] = cm_alias
classes_hash[const.name] = cm_alias
end
@@ -574,8 +743,26 @@ class RDoc::ClassModule < RDoc::Context
def update_includes
includes.reject! do |include|
mod = include.module
- !(String === mod) && RDoc::TopLevel.all_modules_hash[mod.full_name].nil?
end
end
end