2017-11-27 05:45:24 -05:00
|
|
|
# frozen_string_literal: true
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# ClassModule is the base class for objects representing either a class or a
|
|
|
|
# module.
|
|
|
|
|
|
|
|
class RDoc::ClassModule < RDoc::Context
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
##
|
|
|
|
# 1::
|
|
|
|
# RDoc 3.7
|
|
|
|
# * Added visibility, singleton and file to attributes
|
|
|
|
# * Added file to constants
|
|
|
|
# * Added file to includes
|
|
|
|
# * Added file to methods
|
2012-11-26 23:28:14 -05:00
|
|
|
# 2::
|
|
|
|
# RDoc 3.13
|
|
|
|
# * Added extends
|
|
|
|
# 3::
|
|
|
|
# RDoc 4.0
|
|
|
|
# * Added sections
|
|
|
|
# * Added in_files
|
|
|
|
# * Added parent name
|
|
|
|
# * Complete Constant dump
|
|
|
|
|
|
|
|
MARSHAL_VERSION = 3 # :nodoc:
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Constants that are aliases for this class or module
|
|
|
|
|
|
|
|
attr_accessor :constant_aliases
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
##
|
|
|
|
# Comment and the location it came from. Use #add_comment to add comments
|
|
|
|
|
2012-12-13 02:58:47 -05:00
|
|
|
attr_accessor :comment_location
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :diagram # :nodoc:
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Class or module this constant is an alias for
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_accessor :is_alias_for
|
|
|
|
|
|
|
|
##
|
|
|
|
# Return a RDoc::ClassModule of class +class_type+ that is a copy
|
|
|
|
# of module +module+. Used to promote modules to classes.
|
2011-06-16 00:59:24 -04:00
|
|
|
#--
|
|
|
|
# TODO move to RDoc::NormalClass (I think)
|
|
|
|
|
|
|
|
def self.from_module class_type, mod
|
|
|
|
klass = class_type.new mod.name
|
|
|
|
|
|
|
|
mod.comment_location.each do |comment, location|
|
|
|
|
klass.add_comment comment, location
|
|
|
|
end
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
klass.parent = mod.parent
|
|
|
|
klass.section = mod.section
|
|
|
|
klass.viewer = mod.viewer
|
|
|
|
|
|
|
|
klass.attributes.concat mod.attributes
|
|
|
|
klass.method_list.concat mod.method_list
|
|
|
|
klass.aliases.concat mod.aliases
|
|
|
|
klass.external_aliases.concat mod.external_aliases
|
|
|
|
klass.constants.concat mod.constants
|
|
|
|
klass.includes.concat mod.includes
|
2012-11-26 23:28:14 -05:00
|
|
|
klass.extends.concat mod.extends
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
klass.methods_hash.update mod.methods_hash
|
|
|
|
klass.constants_hash.update mod.constants_hash
|
|
|
|
|
|
|
|
klass.current_section = mod.current_section
|
|
|
|
klass.in_files.concat mod.in_files
|
|
|
|
klass.sections.concat mod.sections
|
|
|
|
klass.unmatched_alias_lists = mod.unmatched_alias_lists
|
|
|
|
klass.current_section = mod.current_section
|
|
|
|
klass.visibility = mod.visibility
|
|
|
|
|
|
|
|
klass.classes_hash.update mod.classes_hash
|
|
|
|
klass.modules_hash.update mod.modules_hash
|
|
|
|
klass.metadata.update mod.metadata
|
|
|
|
|
|
|
|
klass.document_self = mod.received_nodoc ? nil : mod.document_self
|
|
|
|
klass.document_children = mod.document_children
|
|
|
|
klass.force_documentation = mod.force_documentation
|
|
|
|
klass.done_documenting = mod.done_documenting
|
|
|
|
|
|
|
|
# update the parent of all children
|
|
|
|
|
|
|
|
(klass.attributes +
|
|
|
|
klass.method_list +
|
|
|
|
klass.aliases +
|
|
|
|
klass.external_aliases +
|
|
|
|
klass.constants +
|
|
|
|
klass.includes +
|
2012-11-26 23:28:14 -05:00
|
|
|
klass.extends +
|
2010-12-19 22:22:49 -05:00
|
|
|
klass.classes +
|
|
|
|
klass.modules).each do |obj|
|
|
|
|
obj.parent = klass
|
|
|
|
obj.full_name = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
klass
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Creates a new ClassModule with +name+ with optional +superclass+
|
|
|
|
#
|
|
|
|
# This is a constructor for subclasses, and must never be called directly.
|
|
|
|
|
|
|
|
def initialize(name, superclass = nil)
|
|
|
|
@constant_aliases = []
|
|
|
|
@diagram = nil
|
|
|
|
@is_alias_for = nil
|
|
|
|
@name = name
|
|
|
|
@superclass = superclass
|
2011-06-16 00:59:24 -04:00
|
|
|
@comment_location = [] # [[comment, location]]
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
super()
|
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
##
|
|
|
|
# Adds +comment+ to this ClassModule's list of comments at +location+. This
|
|
|
|
# method is preferred over #comment= since it allows ri data to be updated
|
|
|
|
# across multiple runs.
|
|
|
|
|
|
|
|
def add_comment comment, location
|
2012-11-26 23:28:14 -05:00
|
|
|
return unless document_self
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
original = comment
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
comment = case comment
|
|
|
|
when RDoc::Comment then
|
|
|
|
comment.normalize
|
|
|
|
else
|
|
|
|
normalize_comment comment
|
|
|
|
end
|
2012-12-13 02:58:47 -05:00
|
|
|
|
2017-11-27 05:45:24 -05:00
|
|
|
if location.parser == RDoc::Parser::C
|
|
|
|
@comment_location.delete_if { |(_, l)| l == location }
|
|
|
|
end
|
2012-12-13 02:58:47 -05:00
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
@comment_location << [comment, location]
|
|
|
|
|
|
|
|
self.comment = original
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def add_things my_things, other_things # :nodoc:
|
|
|
|
other_things.each do |group, things|
|
|
|
|
my_things[group].each { |thing| yield false, thing } if
|
|
|
|
my_things.include? group
|
|
|
|
|
|
|
|
things.each do |thing|
|
|
|
|
yield true, thing
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Ancestors list for this ClassModule: the list of included modules
|
|
|
|
# (classes will add their superclass if any).
|
|
|
|
#
|
|
|
|
# Returns the included classes or modules, not the includes
|
|
|
|
# themselves. The returned values are either String or
|
|
|
|
# RDoc::NormalModule instances (see RDoc::Include#module).
|
|
|
|
#
|
|
|
|
# The values are returned in reverse order of their inclusion,
|
|
|
|
# which is the order suitable for searching methods/attributes
|
|
|
|
# in the ancestors. The superclass, if any, comes last.
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
def ancestors
|
2010-12-19 22:22:49 -05:00
|
|
|
includes.map { |i| i.module }.reverse
|
|
|
|
end
|
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
def aref_prefix # :nodoc:
|
|
|
|
raise NotImplementedError, "missing aref_prefix for #{self.class}"
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# HTML fragment reference for this module or class. See
|
|
|
|
# RDoc::NormalClass#aref and RDoc::NormalModule#aref
|
|
|
|
|
|
|
|
def aref
|
|
|
|
"#{aref_prefix}-#{full_name}"
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# Ancestors of this class or module only
|
|
|
|
|
|
|
|
alias direct_ancestors ancestors
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
2013-07-18 22:26:08 -04:00
|
|
|
# Clears the comment. Used by the Ruby parser.
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
def clear_comment
|
|
|
|
@comment = ''
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2011-06-16 00:59:24 -04:00
|
|
|
# This method is deprecated, use #add_comment instead.
|
|
|
|
#
|
2010-04-01 03:45:16 -04:00
|
|
|
# Appends +comment+ to the current comment, but separated by a rule. Works
|
|
|
|
# more like <tt>+=</tt>.
|
|
|
|
|
2012-12-12 00:16:53 -05:00
|
|
|
def comment= comment # :nodoc:
|
2012-11-26 23:28:14 -05:00
|
|
|
comment = case comment
|
|
|
|
when RDoc::Comment then
|
|
|
|
comment.normalize
|
|
|
|
else
|
|
|
|
normalize_comment comment
|
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
comment = "#{@comment}\n---\n#{comment}" unless @comment.empty?
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
super comment
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Prepares this ClassModule for use by a generator.
|
|
|
|
#
|
2012-11-26 23:28:14 -05:00
|
|
|
# See RDoc::Store#complete
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
def complete min_visibility
|
|
|
|
update_aliases
|
|
|
|
remove_nodoc_children
|
|
|
|
update_includes
|
|
|
|
remove_invisible min_visibility
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# Does this ClassModule or any of its methods have document_self set?
|
|
|
|
|
|
|
|
def document_self_or_methods
|
|
|
|
document_self || method_list.any?{ |m| m.document_self }
|
|
|
|
end
|
|
|
|
|
2012-12-12 00:16:53 -05:00
|
|
|
##
|
|
|
|
# Does this class or module have a comment with content or is
|
|
|
|
# #received_nodoc true?
|
|
|
|
|
|
|
|
def documented?
|
2013-09-18 19:33:36 -04:00
|
|
|
return true if @received_nodoc
|
|
|
|
return false if @comment_location.empty?
|
|
|
|
@comment_location.any? { |comment, _| not comment.empty? }
|
2012-12-12 00:16:53 -05:00
|
|
|
end
|
|
|
|
|
2011-05-13 20:39:16 -04:00
|
|
|
##
|
|
|
|
# Iterates the ancestors of this class or module for which an
|
|
|
|
# RDoc::ClassModule exists.
|
|
|
|
|
|
|
|
def each_ancestor # :yields: module
|
2012-11-26 23:28:14 -05:00
|
|
|
return enum_for __method__ unless block_given?
|
|
|
|
|
2011-05-13 20:39:16 -04:00
|
|
|
ancestors.each do |mod|
|
|
|
|
next if String === mod
|
2012-11-26 23:28:14 -05:00
|
|
|
next if self == mod
|
2011-05-13 20:39:16 -04:00
|
|
|
yield mod
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Looks for a symbol in the #ancestors. See Context#find_local_symbol.
|
|
|
|
|
|
|
|
def find_ancestor_local_symbol symbol
|
2011-05-13 20:39:16 -04:00
|
|
|
each_ancestor do |m|
|
2010-12-19 22:22:49 -05:00
|
|
|
res = m.find_local_symbol(symbol)
|
|
|
|
return res if res
|
|
|
|
end
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
2011-02-01 19:32:30 -05:00
|
|
|
# Finds a class or module with +name+ in this namespace or its descendants
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def find_class_named name
|
2010-04-01 03:45:16 -04:00
|
|
|
return self if full_name == name
|
|
|
|
return self if @name == name
|
|
|
|
|
|
|
|
@classes.values.find do |klass|
|
|
|
|
next if klass == self
|
|
|
|
klass.find_class_named name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Return the fully qualified name of this class or module
|
|
|
|
|
|
|
|
def full_name
|
2012-11-26 23:28:14 -05:00
|
|
|
@full_name ||= if RDoc::ClassModule === parent then
|
|
|
|
"#{parent.full_name}::#{@name}"
|
2010-04-01 03:45:16 -04:00
|
|
|
else
|
|
|
|
@name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
##
|
|
|
|
# TODO: filter included items by #display?
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def marshal_dump # :nodoc:
|
|
|
|
attrs = attributes.sort.map do |attr|
|
2013-09-18 19:33:36 -04:00
|
|
|
next unless attr.display?
|
2011-06-16 00:59:24 -04:00
|
|
|
[ attr.name, attr.rw,
|
|
|
|
attr.visibility, attr.singleton, attr.file_name,
|
|
|
|
]
|
2013-09-18 19:33:36 -04:00
|
|
|
end.compact
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
method_types = methods_by_type.map do |type, visibilities|
|
|
|
|
visibilities = visibilities.map do |visibility, methods|
|
|
|
|
method_names = methods.map do |method|
|
2013-09-18 19:33:36 -04:00
|
|
|
next unless method.display?
|
2011-06-16 00:59:24 -04:00
|
|
|
[method.name, method.file_name]
|
2013-09-18 19:33:36 -04:00
|
|
|
end.compact
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
[visibility, method_names.uniq]
|
|
|
|
end
|
|
|
|
|
|
|
|
[type, visibilities]
|
|
|
|
end
|
|
|
|
|
|
|
|
[ MARSHAL_VERSION,
|
|
|
|
@name,
|
|
|
|
full_name,
|
|
|
|
@superclass,
|
2011-06-16 00:59:24 -04:00
|
|
|
parse(@comment_location),
|
2010-04-01 03:45:16 -04:00
|
|
|
attrs,
|
2013-09-18 19:33:36 -04:00
|
|
|
constants.select { |constant| constant.display? },
|
2010-04-01 03:45:16 -04:00
|
|
|
includes.map do |incl|
|
2013-09-18 19:33:36 -04:00
|
|
|
next unless incl.display?
|
2011-06-16 00:59:24 -04:00
|
|
|
[incl.name, parse(incl.comment), incl.file_name]
|
2013-09-18 19:33:36 -04:00
|
|
|
end.compact,
|
2010-04-01 03:45:16 -04:00
|
|
|
method_types,
|
2012-11-26 23:28:14 -05:00
|
|
|
extends.map do |ext|
|
2013-09-18 19:33:36 -04:00
|
|
|
next unless ext.display?
|
2012-11-26 23:28:14 -05:00
|
|
|
[ext.name, parse(ext.comment), ext.file_name]
|
2013-09-18 19:33:36 -04:00
|
|
|
end.compact,
|
2012-11-26 23:28:14 -05:00
|
|
|
@sections.values,
|
|
|
|
@in_files.map do |tl|
|
2012-11-27 03:54:03 -05:00
|
|
|
tl.relative_name
|
2012-11-26 23:28:14 -05:00
|
|
|
end,
|
|
|
|
parent.full_name,
|
|
|
|
parent.class,
|
2010-04-01 03:45:16 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def marshal_load array # :nodoc:
|
2013-01-22 20:02:24 -05:00
|
|
|
initialize_visibility
|
2010-04-01 03:45:16 -04:00
|
|
|
initialize_methods_etc
|
2011-06-16 00:59:24 -04:00
|
|
|
@current_section = nil
|
|
|
|
@document_self = true
|
|
|
|
@done_documenting = false
|
|
|
|
@parent = nil
|
|
|
|
@temporary_section = nil
|
|
|
|
@visibility = nil
|
2012-11-26 23:28:14 -05:00
|
|
|
@classes = {}
|
|
|
|
@modules = {}
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
@name = array[1]
|
|
|
|
@full_name = array[2]
|
|
|
|
@superclass = array[3]
|
|
|
|
@comment = array[4]
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
@comment_location = if RDoc::Markup::Document === @comment.parts.first then
|
|
|
|
@comment
|
|
|
|
else
|
|
|
|
RDoc::Markup::Document.new @comment
|
|
|
|
end
|
|
|
|
|
|
|
|
array[5].each do |name, rw, visibility, singleton, file|
|
|
|
|
singleton ||= false
|
|
|
|
visibility ||= :public
|
|
|
|
|
|
|
|
attr = RDoc::Attr.new nil, name, rw, nil, singleton
|
|
|
|
|
|
|
|
add_attribute attr
|
|
|
|
attr.visibility = visibility
|
|
|
|
attr.record_location RDoc::TopLevel.new file
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
array[6].each do |constant, comment, file|
|
|
|
|
case constant
|
|
|
|
when RDoc::Constant then
|
|
|
|
add_constant constant
|
|
|
|
else
|
|
|
|
constant = add_constant RDoc::Constant.new(constant, nil, comment)
|
|
|
|
constant.record_location RDoc::TopLevel.new file
|
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
array[7].each do |name, comment, file|
|
|
|
|
incl = add_include RDoc::Include.new(name, comment)
|
|
|
|
incl.record_location RDoc::TopLevel.new file
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
array[8].each do |type, visibilities|
|
|
|
|
visibilities.each do |visibility, methods|
|
|
|
|
@visibility = visibility
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
methods.each do |name, file|
|
2010-04-01 03:45:16 -04:00
|
|
|
method = RDoc::AnyMethod.new nil, name
|
|
|
|
method.singleton = true if type == 'class'
|
2011-06-16 00:59:24 -04:00
|
|
|
method.record_location RDoc::TopLevel.new file
|
2010-04-01 03:45:16 -04:00
|
|
|
add_method method
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
array[9].each do |name, comment, file|
|
|
|
|
ext = add_extend RDoc::Extend.new(name, comment)
|
|
|
|
ext.record_location RDoc::TopLevel.new file
|
|
|
|
end if array[9] # Support Marshal version 1
|
|
|
|
|
|
|
|
sections = (array[10] || []).map do |section|
|
|
|
|
[section.title, section]
|
|
|
|
end
|
|
|
|
|
|
|
|
@sections = Hash[*sections.flatten]
|
|
|
|
@current_section = add_section nil
|
|
|
|
|
|
|
|
@in_files = []
|
|
|
|
|
|
|
|
(array[11] || []).each do |filename|
|
|
|
|
record_location RDoc::TopLevel.new filename
|
|
|
|
end
|
|
|
|
|
|
|
|
@parent_name = array[12]
|
|
|
|
@parent_class = array[13]
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2011-06-16 00:59:24 -04:00
|
|
|
# Merges +class_module+ into this ClassModule.
|
|
|
|
#
|
|
|
|
# The data in +class_module+ is preferred over the receiver.
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
def merge class_module
|
2012-11-26 23:28:14 -05:00
|
|
|
@parent = class_module.parent
|
|
|
|
@parent_name = class_module.parent_name
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
other_document = parse class_module.comment_location
|
2010-04-10 02:36:13 -04:00
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
if other_document then
|
|
|
|
document = parse @comment_location
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
document = document.merge other_document
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
@comment = @comment_location = document
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2011-06-29 17:17:31 -04:00
|
|
|
cm = class_module
|
|
|
|
other_files = cm.in_files
|
|
|
|
|
|
|
|
merge_collections attributes, cm.attributes, other_files do |add, attr|
|
2011-06-16 00:59:24 -04:00
|
|
|
if add then
|
2010-04-01 03:45:16 -04:00
|
|
|
add_attribute attr
|
2011-06-16 00:59:24 -04:00
|
|
|
else
|
|
|
|
@attributes.delete attr
|
|
|
|
@methods_hash.delete attr.pretty_name
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-29 17:17:31 -04:00
|
|
|
merge_collections constants, cm.constants, other_files do |add, const|
|
2011-06-16 00:59:24 -04:00
|
|
|
if add then
|
|
|
|
add_constant const
|
|
|
|
else
|
|
|
|
@constants.delete const
|
|
|
|
@constants_hash.delete const.name
|
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2011-06-29 17:17:31 -04:00
|
|
|
merge_collections includes, cm.includes, other_files do |add, incl|
|
2011-06-16 00:59:24 -04:00
|
|
|
if add then
|
|
|
|
add_include incl
|
|
|
|
else
|
|
|
|
@includes.delete incl
|
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@includes.uniq! # clean up
|
|
|
|
|
|
|
|
merge_collections extends, cm.extends, other_files do |add, ext|
|
|
|
|
if add then
|
|
|
|
add_extend ext
|
|
|
|
else
|
|
|
|
@extends.delete ext
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@extends.uniq! # clean up
|
|
|
|
|
2011-06-29 17:17:31 -04:00
|
|
|
merge_collections method_list, cm.method_list, other_files do |add, meth|
|
2011-06-16 00:59:24 -04:00
|
|
|
if add then
|
|
|
|
add_method meth
|
|
|
|
else
|
|
|
|
@method_list.delete meth
|
|
|
|
@methods_hash.delete meth.pretty_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
merge_sections cm
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2011-06-29 17:17:31 -04:00
|
|
|
# Merges collection +mine+ with +other+ preferring other. +other_files+ is
|
|
|
|
# used to help determine which items should be deleted.
|
|
|
|
#
|
|
|
|
# Yields whether the item should be added or removed (true or false) and the
|
|
|
|
# item to be added or removed.
|
|
|
|
#
|
|
|
|
# merge_collections things, other.things, other.in_files do |add, thing|
|
|
|
|
# if add then
|
|
|
|
# # add the thing
|
|
|
|
# else
|
|
|
|
# # remove the thing
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
|
|
|
def merge_collections mine, other, other_files, &block # :nodoc:
|
2011-06-16 00:59:24 -04:00
|
|
|
my_things = mine. group_by { |thing| thing.file }
|
|
|
|
other_things = other.group_by { |thing| thing.file }
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
remove_things my_things, other_files, &block
|
|
|
|
add_things my_things, other_things, &block
|
|
|
|
end
|
2011-06-29 17:17:31 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# Merges the comments in this ClassModule with the comments in the other
|
|
|
|
# ClassModule +cm+.
|
2011-06-29 17:17:31 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def merge_sections cm # :nodoc:
|
|
|
|
my_sections = sections.group_by { |section| section.title }
|
|
|
|
other_sections = cm.sections.group_by { |section| section.title }
|
|
|
|
|
|
|
|
other_files = cm.in_files
|
|
|
|
|
|
|
|
remove_things my_sections, other_files do |_, section|
|
|
|
|
@sections.delete section.title
|
2011-06-29 17:17:31 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
other_sections.each do |group, sections|
|
|
|
|
if my_sections.include? group
|
|
|
|
my_sections[group].each do |my_section|
|
|
|
|
other_section = cm.sections_hash[group]
|
2011-06-16 00:59:24 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
my_comments = my_section.comments
|
|
|
|
other_comments = other_section.comments
|
|
|
|
|
|
|
|
other_files = other_section.in_files
|
|
|
|
|
|
|
|
merge_collections my_comments, other_comments, other_files do |add, comment|
|
|
|
|
if add then
|
|
|
|
my_section.add_comment comment
|
|
|
|
else
|
|
|
|
my_section.remove_comment comment
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
sections.each do |section|
|
|
|
|
add_section group, section.comments
|
|
|
|
end
|
2011-06-16 00:59:24 -04:00
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Does this object represent a module?
|
|
|
|
|
|
|
|
def module?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Allows overriding the initial name.
|
|
|
|
#
|
|
|
|
# Used for modules and classes that are constant aliases.
|
|
|
|
|
|
|
|
def name= new_name
|
|
|
|
@name = new_name
|
|
|
|
end
|
|
|
|
|
2011-06-16 00:59:24 -04:00
|
|
|
##
|
|
|
|
# Parses +comment_location+ into an RDoc::Markup::Document composed of
|
|
|
|
# multiple RDoc::Markup::Documents with their file set.
|
|
|
|
|
|
|
|
def parse comment_location
|
|
|
|
case comment_location
|
|
|
|
when String then
|
|
|
|
super
|
|
|
|
when Array then
|
|
|
|
docs = comment_location.map do |comment, location|
|
|
|
|
doc = super comment
|
2012-11-26 23:28:14 -05:00
|
|
|
doc.file = location
|
2011-06-16 00:59:24 -04:00
|
|
|
doc
|
|
|
|
end
|
|
|
|
|
|
|
|
RDoc::Markup::Document.new(*docs)
|
2012-11-26 23:28:14 -05:00
|
|
|
when RDoc::Comment then
|
|
|
|
doc = super comment_location.text, comment_location.format
|
|
|
|
doc.file = comment_location.location
|
|
|
|
doc
|
2011-06-16 00:59:24 -04:00
|
|
|
when RDoc::Markup::Document then
|
|
|
|
return comment_location
|
|
|
|
else
|
|
|
|
raise ArgumentError, "unknown comment class #{comment_location.class}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
2012-11-26 23:28:14 -05:00
|
|
|
# Path to this class or module for use with HTML generator output.
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
def path
|
2012-11-26 23:28:14 -05:00
|
|
|
http_url @store.rdoc.generator.class_dir
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Name to use to generate the url:
|
|
|
|
# modules and classes that are aliases for another
|
2011-02-01 19:32:30 -05:00
|
|
|
# module or class return the name of the latter.
|
2010-12-19 22:22:49 -05:00
|
|
|
|
|
|
|
def name_for_path
|
|
|
|
is_alias_for ? is_alias_for.full_name : full_name
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Returns the classes and modules that are not constants
|
|
|
|
# aliasing another class or module. For use by formatters
|
|
|
|
# only (caches its result).
|
|
|
|
|
|
|
|
def non_aliases
|
|
|
|
@non_aliases ||= classes_and_modules.reject { |cm| cm.is_alias_for }
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Updates the child modules or classes of class/module +parent+ by
|
|
|
|
# deleting the ones that have been removed from the documentation.
|
|
|
|
#
|
|
|
|
# +parent_hash+ is either <tt>parent.modules_hash</tt> or
|
|
|
|
# <tt>parent.classes_hash</tt> and +all_hash+ is ::all_modules_hash or
|
|
|
|
# ::all_classes_hash.
|
|
|
|
|
|
|
|
def remove_nodoc_children
|
|
|
|
prefix = self.full_name + '::'
|
|
|
|
|
|
|
|
modules_hash.each_key do |name|
|
|
|
|
full_name = prefix + name
|
2012-11-26 23:28:14 -05:00
|
|
|
modules_hash.delete name unless @store.modules_hash[full_name]
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
classes_hash.each_key do |name|
|
|
|
|
full_name = prefix + name
|
2012-11-26 23:28:14 -05:00
|
|
|
classes_hash.delete name unless @store.classes_hash[full_name]
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def remove_things my_things, other_files # :nodoc:
|
|
|
|
my_things.delete_if do |file, things|
|
|
|
|
next false unless other_files.include? file
|
|
|
|
|
|
|
|
things.each do |thing|
|
|
|
|
yield false, thing
|
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Search record used by RDoc::Generator::JsonIndex
|
|
|
|
|
|
|
|
def search_record
|
|
|
|
[
|
|
|
|
name,
|
|
|
|
full_name,
|
|
|
|
full_name,
|
|
|
|
'',
|
|
|
|
path,
|
|
|
|
'',
|
|
|
|
snippet(@comment_location),
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Sets the store for this class or module and its contained code objects.
|
|
|
|
|
|
|
|
def store= store
|
|
|
|
super
|
|
|
|
|
|
|
|
@attributes .each do |attr| attr.store = store end
|
|
|
|
@constants .each do |const| const.store = store end
|
|
|
|
@includes .each do |incl| incl.store = store end
|
|
|
|
@extends .each do |ext| ext.store = store end
|
|
|
|
@method_list.each do |meth| meth.store = store end
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# Get the superclass of this class. Attempts to retrieve the superclass
|
|
|
|
# object, returns the name if it is not known.
|
|
|
|
|
|
|
|
def superclass
|
2012-11-26 23:28:14 -05:00
|
|
|
@store.find_class_named(@superclass) || @superclass
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Set the superclass of this class to +superclass+
|
|
|
|
|
|
|
|
def superclass=(superclass)
|
|
|
|
raise NoMethodError, "#{full_name} is a module" if module?
|
2010-12-19 22:22:49 -05:00
|
|
|
@superclass = superclass
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s # :nodoc:
|
2010-12-19 22:22:49 -05:00
|
|
|
if is_alias_for then
|
|
|
|
"#{self.class.name} #{self.full_name} -> #{is_alias_for}"
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# 'module' or 'class'
|
|
|
|
|
|
|
|
def type
|
|
|
|
module? ? 'module' : 'class'
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Updates the child modules & classes by replacing the ones that are
|
|
|
|
# aliases through a constant.
|
|
|
|
#
|
|
|
|
# The aliased module/class is replaced in the children and in
|
2012-11-26 23:28:14 -05:00
|
|
|
# RDoc::Store#modules_hash or RDoc::Store#classes_hash
|
2010-12-19 22:22:49 -05:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# Formatters can use the #non_aliases method to retrieve children that
|
|
|
|
# are not aliases, for instance to list the namespace content, since
|
|
|
|
# the aliased modules are included in the constants of the class/module,
|
|
|
|
# that are listed separately.
|
|
|
|
|
|
|
|
def update_aliases
|
|
|
|
constants.each do |const|
|
|
|
|
next unless cm = const.is_alias_for
|
|
|
|
cm_alias = cm.dup
|
|
|
|
cm_alias.name = const.name
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
# Don't move top-level aliases under Object, they look ugly there
|
|
|
|
unless RDoc::TopLevel === cm_alias.parent then
|
|
|
|
cm_alias.parent = self
|
|
|
|
cm_alias.full_name = nil # force update for new parent
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
cm_alias.aliases.clear
|
|
|
|
cm_alias.is_alias_for = cm
|
|
|
|
|
|
|
|
if cm.module? then
|
2012-11-26 23:28:14 -05:00
|
|
|
@store.modules_hash[cm_alias.full_name] = cm_alias
|
2010-12-19 22:22:49 -05:00
|
|
|
modules_hash[const.name] = cm_alias
|
|
|
|
else
|
2012-11-26 23:28:14 -05:00
|
|
|
@store.classes_hash[cm_alias.full_name] = cm_alias
|
2010-12-19 22:22:49 -05:00
|
|
|
classes_hash[const.name] = cm_alias
|
|
|
|
end
|
|
|
|
|
|
|
|
cm.aliases << cm_alias
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Deletes from #includes those whose module has been removed from the
|
|
|
|
# documentation.
|
|
|
|
#--
|
|
|
|
# FIXME: includes are not reliably removed, see _possible_bug test case
|
|
|
|
|
|
|
|
def update_includes
|
|
|
|
includes.reject! do |include|
|
|
|
|
mod = include.module
|
2012-11-26 23:28:14 -05:00
|
|
|
!(String === mod) && @store.modules_hash[mod.full_name].nil?
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
includes.uniq!
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Deletes from #extends those whose module has been removed from the
|
|
|
|
# documentation.
|
|
|
|
#--
|
|
|
|
# FIXME: like update_includes, extends are not reliably removed
|
|
|
|
|
|
|
|
def update_extends
|
|
|
|
extends.reject! do |ext|
|
|
|
|
mod = ext.module
|
|
|
|
|
|
|
|
!(String === mod) && @store.modules_hash[mod.full_name].nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
extends.uniq!
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|