Sync RDoc 6.14.0

This commit is contained in:
Stan Lo 2025-05-22 22:49:04 +01:00 committed by Takashi Kokubun
parent ca1ea95784
commit 03eb777c69
185 changed files with 2008 additions and 1655 deletions

View file

@ -23,7 +23,7 @@ class RDoc::Alias < RDoc::CodeObject
##
# Is this an alias declared in a singleton context?
attr_accessor :singleton
attr_reader :singleton
##
# Source file token stream
@ -34,7 +34,7 @@ class RDoc::Alias < RDoc::CodeObject
# Creates a new Alias with a token stream of +text+ that aliases +old_name+
# to +new_name+, has +comment+ and is a +singleton+ context.
def initialize(text, old_name, new_name, comment, singleton = false)
def initialize(text, old_name, new_name, comment, singleton: false)
super()
@text = text
@ -59,13 +59,6 @@ class RDoc::Alias < RDoc::CodeObject
"#alias-#{type}-#{html_name}"
end
##
# Full old name including namespace
def full_old_name
@full_name || "#{parent.name}#{pretty_old_name}"
end
##
# HTML id-friendly version of +#new_name+.

View file

@ -29,10 +29,6 @@ class RDoc::AnyMethod < RDoc::MethodAttr
# The section title of the method (if defined in a C file via +:category:+)
attr_accessor :section_title
# Parameters for this method
attr_accessor :params
##
# If true this method uses +super+ to call a superclass version
@ -43,8 +39,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr
##
# Creates a new AnyMethod with a token stream +text+ and +name+
def initialize text, name
super
def initialize(text, name, singleton: false)
super(text, name, singleton: singleton)
@c_function = nil
@dont_rename_initialize = false
@ -56,11 +52,10 @@ class RDoc::AnyMethod < RDoc::MethodAttr
##
# Adds +an_alias+ as an alias for this method in +context+.
def add_alias an_alias, context = nil
method = self.class.new an_alias.text, an_alias.new_name
def add_alias(an_alias, context = nil)
method = self.class.new an_alias.text, an_alias.new_name, singleton: singleton
method.record_location an_alias.file
method.singleton = self.singleton
method.params = self.params
method.visibility = self.visibility
method.comment = an_alias.comment
@ -109,8 +104,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr
#
# See also #param_seq
def call_seq= call_seq
return if call_seq.empty?
def call_seq=(call_seq)
return if call_seq.nil? || call_seq.empty?
@call_seq = call_seq
end
@ -181,7 +176,7 @@ class RDoc::AnyMethod < RDoc::MethodAttr
# * #full_name
# * #parent_name
def marshal_load array
def marshal_load(array)
initialize_visibility
@dont_rename_initialize = nil
@ -198,7 +193,7 @@ class RDoc::AnyMethod < RDoc::MethodAttr
@full_name = array[2]
@singleton = array[3]
@visibility = array[4]
@comment = array[5]
@comment = RDoc::Comment.from_document array[5]
@call_seq = array[6]
@block_params = array[7]
# 8 handled below
@ -210,8 +205,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr
@section_title = array[14]
@is_alias_for = array[15]
array[8].each do |new_name, comment|
add_alias RDoc::Alias.new(nil, @name, new_name, comment, @singleton)
array[8].each do |new_name, document|
add_alias RDoc::Alias.new(nil, @name, new_name, RDoc::Comment.from_document(document), singleton: @singleton)
end
@parent_name ||= if @full_name =~ /#/ then
@ -314,7 +309,7 @@ class RDoc::AnyMethod < RDoc::MethodAttr
##
# Sets the store for this method and its referenced code objects.
def store= store
def store=(store)
super
@file = @store.add_file @file.full_name if @file

View file

@ -22,18 +22,17 @@ class RDoc::Attr < RDoc::MethodAttr
# Creates a new Attr with body +text+, +name+, read/write status +rw+ and
# +comment+. +singleton+ marks this as a class attribute.
def initialize(text, name, rw, comment, singleton = false)
super text, name
def initialize(text, name, rw, comment, singleton: false)
super(text, name, singleton: singleton)
@rw = rw
@singleton = singleton
self.comment = comment
end
##
# Attributes are equal when their names, singleton and rw are identical
def == other
def ==(other)
self.class == other.class and
self.name == other.name and
self.rw == other.rw and
@ -44,9 +43,7 @@ class RDoc::Attr < RDoc::MethodAttr
# Add +an_alias+ as an attribute in +context+.
def add_alias(an_alias, context)
new_attr = self.class.new(self.text, an_alias.new_name, self.rw,
self.comment, self.singleton)
new_attr = self.class.new(text, an_alias.new_name, rw, comment, singleton: singleton)
new_attr.record_location an_alias.file
new_attr.visibility = self.visibility
new_attr.is_alias_for = self
@ -121,7 +118,7 @@ class RDoc::Attr < RDoc::MethodAttr
# * #full_name
# * #parent_name
def marshal_load array
def marshal_load(array)
initialize_visibility
@aliases = []
@ -136,7 +133,7 @@ class RDoc::Attr < RDoc::MethodAttr
@full_name = array[2]
@rw = array[3]
@visibility = array[4]
@comment = array[5]
@comment = RDoc::Comment.from_document array[5]
@singleton = array[6] || false # MARSHAL_VERSION == 0
# 7 handled below
@parent_name = array[8]
@ -148,7 +145,7 @@ class RDoc::Attr < RDoc::MethodAttr
@parent_name ||= @full_name.split('#', 2).first
end
def pretty_print q # :nodoc:
def pretty_print(q) # :nodoc:
q.group 2, "[#{self.class.name} #{full_name} #{rw} #{visibility}", "]" do
unless comment.empty? then
q.breakable

View file

@ -34,8 +34,6 @@ class RDoc::ClassModule < RDoc::Context
attr_accessor :comment_location
attr_accessor :diagram # :nodoc:
##
# Class or module this constant is an alias for
@ -47,7 +45,7 @@ class RDoc::ClassModule < RDoc::Context
#--
# TODO move to RDoc::NormalClass (I think)
def self.from_module class_type, mod
def self.from_module(class_type, mod)
klass = class_type.new mod.name
mod.comment_location.each do |comment, location|
@ -56,7 +54,6 @@ class RDoc::ClassModule < RDoc::Context
klass.parent = mod.parent
klass.section = mod.section
klass.viewer = mod.viewer
klass.attributes.concat mod.attributes
klass.method_list.concat mod.method_list
@ -110,7 +107,6 @@ class RDoc::ClassModule < RDoc::Context
def initialize(name, superclass = nil)
@constant_aliases = []
@diagram = nil
@is_alias_for = nil
@name = name
@superclass = superclass
@ -124,7 +120,7 @@ class RDoc::ClassModule < RDoc::Context
# method is preferred over #comment= since it allows ri data to be updated
# across multiple runs.
def add_comment comment, location
def add_comment(comment, location)
return unless document_self
original = comment
@ -145,7 +141,7 @@ class RDoc::ClassModule < RDoc::Context
self.comment = original
end
def add_things my_things, other_things # :nodoc:
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
@ -202,7 +198,7 @@ class RDoc::ClassModule < RDoc::Context
# Appends +comment+ to the current comment, but separated by a rule. Works
# more like <tt>+=</tt>.
def comment= comment # :nodoc:
def comment=(comment) # :nodoc:
comment = case comment
when RDoc::Comment then
comment.normalize
@ -220,11 +216,12 @@ class RDoc::ClassModule < RDoc::Context
#
# See RDoc::Store#complete
def complete min_visibility
def complete(min_visibility)
update_aliases
remove_nodoc_children
embed_mixins
update_includes
update_extends
remove_invisible min_visibility
end
@ -262,7 +259,7 @@ class RDoc::ClassModule < RDoc::Context
##
# Looks for a symbol in the #ancestors. See Context#find_local_symbol.
def find_ancestor_local_symbol symbol
def find_ancestor_local_symbol(symbol)
each_ancestor do |m|
res = m.find_local_symbol(symbol)
return res if res
@ -274,7 +271,7 @@ class RDoc::ClassModule < RDoc::Context
##
# Finds a class or module with +name+ in this namespace or its descendants
def find_class_named name
def find_class_named(name)
return self if full_name == name
return self if @name == name
@ -295,6 +292,25 @@ class RDoc::ClassModule < RDoc::Context
end
end
##
# Return array of full_name splitted by +::+.
def nesting_namespaces
@namespaces ||= full_name.split("::").reject(&:empty?)
end
##
# Return array of fully qualified nesting namespaces.
#
# For example, if full_name is +A::B::C+, this method returns <code>["A", "A::B", "A::B::C"]</code>
def fully_qualified_nesting_namespaces
return nesting_namespaces if nesting_namespaces.length < 2
@fqns ||= nesting_namespaces.inject([]) do |list, n|
list << (list.empty? ? n : "#{list.last}::#{n}")
end
end
##
# TODO: filter included items by #display?
@ -344,7 +360,7 @@ class RDoc::ClassModule < RDoc::Context
]
end
def marshal_load array # :nodoc:
def marshal_load(array) # :nodoc:
initialize_visibility
initialize_methods_etc
@current_section = nil
@ -359,37 +375,39 @@ class RDoc::ClassModule < RDoc::Context
@name = array[1]
@full_name = array[2]
@superclass = array[3]
@comment = array[4]
document = array[4]
@comment_location = if RDoc::Markup::Document === @comment.parts.first then
@comment
@comment = RDoc::Comment.from_document document
@comment_location = if RDoc::Markup::Document === document.parts.first then
document
else
RDoc::Markup::Document.new @comment
RDoc::Markup::Document.new document
end
array[5].each do |name, rw, visibility, singleton, file|
singleton ||= false
visibility ||= :public
attr = RDoc::Attr.new nil, name, rw, nil, singleton
attr = RDoc::Attr.new nil, name, rw, nil, singleton: singleton
add_attribute attr
attr.visibility = visibility
attr.record_location RDoc::TopLevel.new file
end
array[6].each do |constant, comment, file|
array[6].each do |constant, document, file|
case constant
when RDoc::Constant then
add_constant constant
else
constant = add_constant RDoc::Constant.new(constant, nil, comment)
constant = add_constant RDoc::Constant.new(constant, nil, RDoc::Comment.from_document(document))
constant.record_location RDoc::TopLevel.new file
end
end
array[7].each do |name, comment, file|
incl = add_include RDoc::Include.new(name, comment)
array[7].each do |name, document, file|
incl = add_include RDoc::Include.new(name, RDoc::Comment.from_document(document))
incl.record_location RDoc::TopLevel.new file
end
@ -398,16 +416,15 @@ class RDoc::ClassModule < RDoc::Context
@visibility = visibility
methods.each do |name, file|
method = RDoc::AnyMethod.new nil, name
method.singleton = true if type == 'class'
method = RDoc::AnyMethod.new nil, name, singleton: type == 'class'
method.record_location RDoc::TopLevel.new file
add_method method
end
end
end
array[9].each do |name, comment, file|
ext = add_extend RDoc::Extend.new(name, comment)
array[9].each do |name, document, file|
ext = add_extend RDoc::Extend.new(name, RDoc::Comment.from_document(document))
ext.record_location RDoc::TopLevel.new file
end if array[9] # Support Marshal version 1
@ -433,7 +450,7 @@ class RDoc::ClassModule < RDoc::Context
#
# The data in +class_module+ is preferred over the receiver.
def merge class_module
def merge(class_module)
@parent = class_module.parent
@parent_name = class_module.parent_name
@ -444,7 +461,8 @@ class RDoc::ClassModule < RDoc::Context
document = document.merge other_document
@comment = @comment_location = document
@comment = RDoc::Comment.from_document(document)
@comment_location = document
end
cm = class_module
@ -517,7 +535,7 @@ class RDoc::ClassModule < RDoc::Context
# end
# end
def merge_collections mine, other, other_files, &block # :nodoc:
def merge_collections(mine, other, other_files, &block) # :nodoc:
my_things = mine. group_by { |thing| thing.file }
other_things = other.group_by { |thing| thing.file }
@ -529,7 +547,7 @@ class RDoc::ClassModule < RDoc::Context
# Merges the comments in this ClassModule with the comments in the other
# ClassModule +cm+.
def merge_sections cm # :nodoc:
def merge_sections(cm) # :nodoc:
my_sections = sections.group_by { |section| section.title }
other_sections = cm.sections.group_by { |section| section.title }
@ -577,7 +595,7 @@ class RDoc::ClassModule < RDoc::Context
#
# Used for modules and classes that are constant aliases.
def name= new_name
def name=(new_name)
@name = new_name
end
@ -585,7 +603,7 @@ class RDoc::ClassModule < RDoc::Context
# Parses +comment_location+ into an RDoc::Markup::Document composed of
# multiple RDoc::Markup::Documents with their file set.
def parse comment_location
def parse(comment_location)
case comment_location
when String then
super
@ -612,7 +630,9 @@ class RDoc::ClassModule < RDoc::Context
# Path to this class or module for use with HTML generator output.
def path
http_url @store.rdoc.generator.class_dir
prefix = options.class_module_path_prefix
return http_url unless prefix
File.join(prefix, http_url)
end
##
@ -655,7 +675,7 @@ class RDoc::ClassModule < RDoc::Context
end
end
def remove_things my_things, other_files # :nodoc:
def remove_things(my_things, other_files) # :nodoc:
my_things.delete_if do |file, things|
next false unless other_files.include? file
@ -685,7 +705,7 @@ class RDoc::ClassModule < RDoc::Context
##
# Sets the store for this class or module and its contained code objects.
def store= store
def store=(store)
super
@attributes .each do |attr| attr.store = store end

View file

@ -44,7 +44,7 @@ class RDoc::Constant < RDoc::CodeObject
##
# Constants are ordered by name
def <=> other
def <=>(other)
return unless self.class === other
[parent_name, name] <=> [other.parent_name, other.name]
@ -53,7 +53,7 @@ class RDoc::Constant < RDoc::CodeObject
##
# Constants are equal when their #parent and #name is the same
def == other
def ==(other)
self.class == other.class and
@parent == other.parent and
@name == other.name
@ -132,8 +132,8 @@ class RDoc::Constant < RDoc::CodeObject
# * #full_name
# * #parent_name
def marshal_load array
initialize array[1], nil, array[5]
def marshal_load(array)
initialize array[1], nil, RDoc::Comment.from_document(array[5])
@full_name = array[2]
@visibility = array[3] || :public
@ -154,7 +154,7 @@ class RDoc::Constant < RDoc::CodeObject
"#{@parent.path}##{@name}"
end
def pretty_print q # :nodoc:
def pretty_print(q) # :nodoc:
q.group 2, "[#{self.class.name} #{full_name}", "]" do
unless comment.empty? then
q.breakable
@ -168,7 +168,7 @@ class RDoc::Constant < RDoc::CodeObject
##
# Sets the store for this class or module and its contained code objects.
def store= store
def store=(store)
super
@file = @store.add_file @file.full_name if @file

View file

@ -180,7 +180,7 @@ class RDoc::Context < RDoc::CodeObject
#
# Currently only RDoc::Extend and RDoc::Include are supported.
def add klass, name, comment
def add(klass, name, comment)
if RDoc::Extend == klass then
ext = RDoc::Extend.new name, comment
add_extend ext
@ -195,7 +195,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Adds +an_alias+ that is automatically resolved
def add_alias an_alias
def add_alias(an_alias)
return an_alias unless @document_self
method_attr = find_method(an_alias.old_name, an_alias.singleton) ||
@ -222,7 +222,7 @@ class RDoc::Context < RDoc::CodeObject
# if method +foo+ exists, but <tt>attr_accessor :foo</tt> will be registered
# if method +foo+ exists, but <tt>foo=</tt> does not.
def add_attribute attribute
def add_attribute(attribute)
return attribute unless @document_self
# mainly to check for redefinition of an attribute as a method
@ -285,7 +285,7 @@ class RDoc::Context < RDoc::CodeObject
# unless it later sees <tt>class Container</tt>. +add_class+ automatically
# upgrades +given_name+ to a class in this case.
def add_class class_type, given_name, superclass = '::Object'
def add_class(class_type, given_name, superclass = '::Object')
# superclass +nil+ is passed by the C parser in the following cases:
# - registering Object in 1.8 (correct)
# - registering BasicObject in 1.9 (correct)
@ -401,7 +401,7 @@ class RDoc::Context < RDoc::CodeObject
# unless #done_documenting is +true+. Sets the #parent of +mod+
# to +self+, and its #section to #current_section. Returns +mod+.
def add_class_or_module mod, self_hash, all_hash
def add_class_or_module(mod, self_hash, all_hash)
mod.section = current_section # TODO declaring context? something is
# wrong here...
mod.parent = self
@ -426,7 +426,7 @@ class RDoc::Context < RDoc::CodeObject
# Adds +constant+ if not already there. If it is, updates the comment,
# value and/or is_alias_for of the known constant if they were empty/nil.
def add_constant constant
def add_constant(constant)
return constant unless @document_self
# HACK: avoid duplicate 'PI' & 'E' in math.c (1.8.7 source code)
@ -451,7 +451,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Adds included module +include+ which should be an RDoc::Include
def add_include include
def add_include(include)
add_to @includes, include
include
@ -460,7 +460,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Adds extension module +ext+ which should be an RDoc::Extend
def add_extend ext
def add_extend(ext)
add_to @extends, ext
ext
@ -470,7 +470,7 @@ class RDoc::Context < RDoc::CodeObject
# Adds +method+ if not already there. If it is (as method or attribute),
# updates the comment if it was empty.
def add_method method
def add_method(method)
return method unless @document_self
# HACK: avoid duplicate 'new' in io.c & struct.c (1.8.7 source code)
@ -482,7 +482,7 @@ class RDoc::Context < RDoc::CodeObject
known.comment = method.comment if known.comment.empty?
previously = ", previously in #{known.file}" unless
method.file == known.file
@store.rdoc.options.warn \
@store.options.warn \
"Duplicate method #{known.full_name} in #{method.file}#{previously}"
end
else
@ -524,7 +524,7 @@ class RDoc::Context < RDoc::CodeObject
# Adds an alias from +from+ (a class or module) to +name+ which was defined
# in +file+.
def add_module_alias from, from_name, to, file
def add_module_alias(from, from_name, to, file)
return from if @done_documenting
to_full_name = child_name to.name
@ -583,7 +583,7 @@ class RDoc::Context < RDoc::CodeObject
#
# See also RDoc::Context::Section
def add_section title, comment = nil
def add_section(title, comment = nil)
if section = @sections[title] then
section.add_comment comment if comment
else
@ -597,7 +597,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Adds +thing+ to the collection +array+
def add_to array, thing
def add_to(array, thing)
array << thing if @document_self
thing.parent = self
@ -629,7 +629,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Creates the full name for a child with +name+
def child_name name
def child_name(name)
if name =~ /^:+/
$' #'
elsif RDoc::TopLevel === self then
@ -688,13 +688,6 @@ class RDoc::Context < RDoc::CodeObject
section
end
##
# Is part of this thing was defined in +file+?
def defined_in?(file)
@in_files.include?(file)
end
def display(method_attr) # :nodoc:
if method_attr.is_a? RDoc::Attr
"#{method_attr.definition} #{method_attr.pretty_name}"
@ -713,13 +706,6 @@ class RDoc::Context < RDoc::CodeObject
def each_ancestor(&_) # :nodoc:
end
##
# Iterator for attributes
def each_attribute # :yields: attribute
@attributes.each { |a| yield a }
end
##
# Iterator for classes and modules
@ -727,27 +713,6 @@ class RDoc::Context < RDoc::CodeObject
classes_and_modules.sort.each(&block)
end
##
# Iterator for constants
def each_constant # :yields: constant
@constants.each {|c| yield c}
end
##
# Iterator for included modules
def each_include # :yields: include
@includes.each do |i| yield i end
end
##
# Iterator for extension modules
def each_extend # :yields: extend
@extends.each do |e| yield e end
end
##
# Iterator for methods
@ -847,13 +812,6 @@ class RDoc::Context < RDoc::CodeObject
end
end
##
# Finds a file with +name+ in this context
def find_file_named name
@store.find_file_named name
end
##
# Finds an instance method with +name+ in this context
@ -871,7 +829,7 @@ class RDoc::Context < RDoc::CodeObject
find_attribute_named(symbol) or
find_external_alias_named(symbol) or
find_module_named(symbol) or
find_file_named(symbol)
@store.find_file_named(symbol)
end
##
@ -973,10 +931,10 @@ class RDoc::Context < RDoc::CodeObject
##
# URL for this with a +prefix+
def http_url(prefix)
def http_url
path = name_for_path
path = path.gsub(/<<\s*(\w*)/, 'from-\1') if path =~ /<</
path = [prefix] + path.split('::')
path = path.split('::')
File.join(*path.compact) + '.html'
end
@ -1012,7 +970,7 @@ class RDoc::Context < RDoc::CodeObject
# If +section+ is provided only methods in that RDoc::Context::Section will
# be returned.
def methods_by_type section = nil
def methods_by_type(section = nil)
methods = {}
TYPES.each do |type|
@ -1104,7 +1062,7 @@ class RDoc::Context < RDoc::CodeObject
#--
# TODO mark the visibility of attributes in the template (if not public?)
def remove_invisible min_visibility
def remove_invisible(min_visibility)
return if [:private, :nodoc].include? min_visibility
remove_invisible_in @method_list, min_visibility
remove_invisible_in @attributes, min_visibility
@ -1114,7 +1072,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Only called when min_visibility == :public or :private
def remove_invisible_in array, min_visibility # :nodoc:
def remove_invisible_in(array, min_visibility) # :nodoc:
if min_visibility == :public then
array.reject! { |e|
e.visibility != :public and not e.force_documentation
@ -1130,7 +1088,7 @@ class RDoc::Context < RDoc::CodeObject
# Tries to resolve unmatched aliases when a method or attribute has just
# been added.
def resolve_aliases added
def resolve_aliases(added)
# resolve any pending unmatched aliases
key = added.pretty_name
unmatched_alias_list = @unmatched_alias_lists[key]
@ -1181,7 +1139,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Sets the current section to a section with +title+. See also #add_section
def set_current_section title, comment
def set_current_section(title, comment)
@current_section = add_section title, comment
end
@ -1246,7 +1204,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Upgrades NormalModule +mod+ in +enclosing+ to a +class_type+
def upgrade_to_class mod, class_type, enclosing
def upgrade_to_class(mod, class_type, enclosing)
enclosing.modules_hash.delete mod.name
klass = RDoc::ClassModule.from_module class_type, mod

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'cgi/util'
require 'cgi/escape'
##
# A section of documentation like:
@ -39,7 +39,7 @@ class RDoc::Context::Section
##
# Creates a new section with +title+ and +comment+
def initialize parent, title, comment
def initialize(parent, title, comment)
@parent = parent
@title = title ? title.strip : title
@ -51,7 +51,7 @@ class RDoc::Context::Section
##
# Sections are equal when they have the same #title
def == other
def ==(other)
self.class === other and @title == other.title
end
@ -60,20 +60,11 @@ class RDoc::Context::Section
##
# Adds +comment+ to this section
def add_comment comment
comment = extract_comment comment
return if comment.empty?
case comment
when RDoc::Comment then
@comments << comment
when RDoc::Markup::Document then
@comments.concat comment.parts
when Array then
@comments.concat comment
else
raise TypeError, "unknown comment type: #{comment.inspect}"
def add_comment(comment)
comments = Array(comment)
comments.each do |c|
extracted_comment = extract_comment(c)
@comments << extracted_comment unless extracted_comment.empty?
end
end
@ -95,12 +86,8 @@ class RDoc::Context::Section
# # :section: The title
# # The body
def extract_comment comment
def extract_comment(comment)
case comment
when Array then
comment.map do |c|
extract_comment c
end
when nil
RDoc::Comment.new ''
when RDoc::Comment then
@ -115,8 +102,6 @@ class RDoc::Context::Section
end
end
comment
when RDoc::Markup::Document then
comment
else
raise TypeError, "unknown comment #{comment.inspect}"
@ -135,20 +120,7 @@ class RDoc::Context::Section
# The files comments in this section come from
def in_files
return [] if @comments.empty?
case @comments
when Array then
@comments.map do |comment|
comment.file
end
when RDoc::Markup::Document then
@comment.parts.map do |document|
document.file
end
else
raise RDoc::Error, "BUG: unknown comment class #{@comments.class}"
end
@comments.map(&:file)
end
##
@ -166,11 +138,11 @@ class RDoc::Context::Section
##
# De-serializes this Section. The section parent must be restored manually.
def marshal_load array
def marshal_load(array)
@parent = nil
@title = array[1]
@comments = array[2]
@comments = array[2].parts.map { |doc| RDoc::Comment.from_document(doc) }
end
##
@ -178,26 +150,7 @@ class RDoc::Context::Section
# multiple RDoc::Markup::Documents with their file set.
def parse
case @comments
when String then
super
when Array then
docs = @comments.map do |comment, location|
doc = super comment
doc.file = location if location
doc
end
RDoc::Markup::Document.new(*docs)
when RDoc::Comment then
doc = super @comments.text, comments.format
doc.file = @comments.location
doc
when RDoc::Markup::Document then
return @comments
else
raise ArgumentError, "unknown comment class #{comments.class}"
end
RDoc::Markup::Document.new(*@comments.map(&:parse))
end
##
@ -213,20 +166,9 @@ class RDoc::Context::Section
# Removes a comment from this section if it is from the same file as
# +comment+
def remove_comment comment
return if @comments.empty?
case @comments
when Array then
@comments.delete_if do |my_comment|
my_comment.file == comment.file
end
when RDoc::Markup::Document then
@comments.parts.delete_if do |document|
document.file == comment.file.name
end
else
raise RDoc::Error, "BUG: unknown comment class #{@comments.class}"
def remove_comment(target_comment)
@comments.delete_if do |stored_comment|
stored_comment.file == target_comment.file
end
end

View file

@ -63,19 +63,13 @@ class RDoc::MethodAttr < RDoc::CodeObject
attr_reader :arglists
##
# Pretty parameter list for this method
attr_reader :param_seq
##
# Creates a new MethodAttr from token stream +text+ and method or attribute
# name +name+.
#
# Usually this is called by super from a subclass.
def initialize text, name
def initialize(text, name, singleton: false)
super()
@text = text
@ -84,21 +78,20 @@ class RDoc::MethodAttr < RDoc::CodeObject
@aliases = []
@is_alias_for = nil
@parent_name = nil
@singleton = nil
@singleton = singleton
@visibility = :public
@see = false
@arglists = nil
@block_params = nil
@call_seq = nil
@param_seq = nil
@params = nil
end
##
# Resets cached data for the object so it can be rebuilt by accessor methods
def initialize_copy other # :nodoc:
def initialize_copy(other) # :nodoc:
@full_name = nil
end
@ -118,7 +111,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
[other.singleton ? 0 : 1, other.name_ord_range, other.name]
end
def == other # :nodoc:
def ==(other) # :nodoc:
equal?(other) or self.class == other.class and full_name == other.full_name
end
@ -157,7 +150,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
##
# Sets the store for this class or module and its contained code objects.
def store= store
def store=(store)
super
@file = @store.add_file @file.full_name if @file
@ -175,7 +168,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
return find_method_or_attribute name[0..-2]
end
def find_method_or_attribute name # :nodoc:
def find_method_or_attribute(name) # :nodoc:
return nil unless parent.respond_to? :ancestors
searched = parent.ancestors
@ -289,7 +282,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
# HTML id-friendly method/attribute name
def html_name
require 'cgi/util'
require 'cgi/escape'
CGI.escape(@name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '')
end
@ -320,19 +313,6 @@ class RDoc::MethodAttr < RDoc::CodeObject
@singleton ? '::' : '#'
end
##
# Name for output to HTML. For class methods the full name with a "." is
# used like +SomeClass.method_name+. For instance methods the class name is
# used if +context+ does not match the parent.
#
# This is to help prevent people from using :: to call class methods.
def output_name context
return "#{name_prefix}#{@name}" if context == parent
"#{parent_name}#{@singleton ? '.' : '#'}#{@name}"
end
##
# Method/attribute name with class/instance indicator
@ -361,7 +341,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
@parent_name || super
end
def pretty_print q # :nodoc:
def pretty_print(q) # :nodoc:
alias_for =
if @is_alias_for.respond_to? :name then
"alias for #{@is_alias_for.name}"

View file

@ -23,13 +23,13 @@ class RDoc::Mixin < RDoc::CodeObject
##
# Mixins are sorted by name
def <=> other
def <=>(other)
return unless self.class === other
name <=> other.name
end
def == other # :nodoc:
def ==(other) # :nodoc:
self.class === other and @name == other.name
end
@ -107,7 +107,7 @@ class RDoc::Mixin < RDoc::CodeObject
##
# Sets the store for this class or module and its contained code objects.
def store= store
def store=(store)
super
@file = @store.add_file @file.full_name if @file

View file

@ -53,7 +53,7 @@ class RDoc::NormalClass < RDoc::ClassModule
display
end
def pretty_print q # :nodoc:
def pretty_print(q) # :nodoc:
superclass = @superclass ? " < #{@superclass}" : nil
q.group 2, "[class #{full_name}#{superclass}", "]" do

View file

@ -29,7 +29,7 @@ class RDoc::NormalModule < RDoc::ClassModule
true
end
def pretty_print q # :nodoc:
def pretty_print(q) # :nodoc:
q.group 2, "[module #{full_name}:", "]" do
q.breakable
q.text "includes:"

View file

@ -24,7 +24,7 @@ class RDoc::Require < RDoc::CodeObject
self.class,
object_id,
@name,
parent_file_name,
@parent ? @parent.base_name : '(unknown)'
]
end

View file

@ -22,7 +22,7 @@ class RDoc::SingleClass < RDoc::ClassModule
"class << #{full_name}"
end
def pretty_print q # :nodoc:
def pretty_print(q) # :nodoc:
q.group 2, "[class << #{full_name}", "]" do
next
end

View file

@ -6,11 +6,6 @@ class RDoc::TopLevel < RDoc::Context
MARSHAL_VERSION = 0 # :nodoc:
##
# This TopLevel's File::Stat struct
attr_accessor :file_stat
##
# Relative name of this file
@ -28,8 +23,6 @@ class RDoc::TopLevel < RDoc::Context
attr_reader :classes_or_modules
attr_accessor :diagram # :nodoc:
##
# The parser class that processed this file
@ -40,13 +33,11 @@ class RDoc::TopLevel < RDoc::Context
# is being generated outside the source dir +relative_name+ is relative to
# the source directory.
def initialize absolute_name, relative_name = absolute_name
def initialize(absolute_name, relative_name = absolute_name)
super()
@name = nil
@absolute_name = absolute_name
@relative_name = relative_name
@file_stat = File.stat(absolute_name) rescue nil # HACK for testing
@diagram = nil
@parser = nil
@classes_or_modules = []
@ -64,7 +55,7 @@ class RDoc::TopLevel < RDoc::Context
##
# An RDoc::TopLevel is equal to another with the same relative_name
def == other
def ==(other)
self.class === other and @relative_name == other.relative_name
end
@ -82,7 +73,7 @@ class RDoc::TopLevel < RDoc::Context
##
# Adds +constant+ to +Object+ instead of +self+.
def add_constant constant
def add_constant(constant)
object_class.record_location self
return constant unless @document_self
object_class.add_constant constant
@ -110,7 +101,7 @@ class RDoc::TopLevel < RDoc::Context
# Adds class or module +mod+. Used in the building phase
# by the Ruby parser.
def add_to_classes_or_modules mod
def add_to_classes_or_modules(mod)
@classes_or_modules << mod
end
@ -137,7 +128,7 @@ class RDoc::TopLevel < RDoc::Context
# TODO Why do we search through all classes/modules found, not just the
# ones of this instance?
def find_class_or_module name
def find_class_or_module(name)
@store.find_class_or_module name
end
@ -173,10 +164,8 @@ class RDoc::TopLevel < RDoc::Context
##
# URL for this with a +prefix+
def http_url(prefix)
path = [prefix, @relative_name.tr('.', '_')]
File.join(*path.compact) + '.html'
def http_url
@relative_name.tr('.', '_') + '.html'
end
def inspect # :nodoc:
@ -188,13 +177,6 @@ class RDoc::TopLevel < RDoc::Context
]
end
##
# Time this file was last modified, if known
def last_modified
@file_stat ? file_stat.mtime : nil
end
##
# Dumps this TopLevel for use by ri. See also #marshal_load
@ -210,13 +192,11 @@ class RDoc::TopLevel < RDoc::Context
##
# Loads this TopLevel from +array+.
def marshal_load array # :nodoc:
def marshal_load(array) # :nodoc:
initialize array[1]
@parser = array[2]
@comment = array[3]
@file_stat = nil
@comment = RDoc::Comment.from_document array[3]
end
##
@ -246,10 +226,12 @@ class RDoc::TopLevel < RDoc::Context
# Path to this file for use with HTML generator output.
def path
http_url @store.rdoc.generator.file_dir
prefix = options.file_path_prefix
return http_url unless prefix
File.join(prefix, http_url)
end
def pretty_print q # :nodoc:
def pretty_print(q) # :nodoc:
q.group 2, "[#{self.class}: ", "]" do
q.text "base name: #{base_name.inspect}"
q.breakable