Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make RDoc handle the case where it encounters an alias to a method be…

…fore the

method, since the alias and the method live in different files.
  • Loading branch information...
commit 9ef31cc4890a165e6a06cf53954284cae560bbf3 1 parent 460ea76
designingpatts authored
View
3  History.txt
@@ -10,6 +10,9 @@ to polish RDoc for Ruby 1.9.1.
* Explicitly set the html template's text color, so that the generated
documentation will display correctly on browsers with custom text and
background color settings (thanks to Luther Thompson).
+ * Ensure that RDoc correctly will associate an alias and a method, even
+ if it encounters the alias first because the alias lives in a different
+ file.
=== 2.2.0 / 2008-09-19
This version includes some significant enhancements to ri. See RI.txt for
View
14 lib/rdoc/code_objects.rb
@@ -314,6 +314,14 @@ def add_module(class_type, name)
def add_method(a_method)
a_method.visibility = @visibility
add_to(@method_list, a_method)
+
+ unmatched_alias_list = @unmatched_alias_lists[a_method.name]
+ if unmatched_alias_list then
+ unmatched_alias_list.each do |unmatched_alias|
+ add_alias(unmatched_alias)
+ @aliases.delete(unmatched_alias)
+ end
+ end
end
def add_attribute(an_attribute)
@@ -333,6 +341,8 @@ def add_alias(an_alias)
add_method(new_meth)
else
add_to(@aliases, an_alias)
+ unmatched_alias_list = @unmatched_alias_lists[an_alias.old_name] ||= []
+ unmatched_alias_list.push(an_alias)
end
an_alias
@@ -392,6 +402,10 @@ def initialize_methods_etc
@requires = []
@includes = []
@constants = []
+
+ # This Hash maps a method name to a list of unmatched
+ # aliases (aliases of a method not yet encountered).
+ @unmatched_alias_lists = {}
end
# and remove classes and modules when we see a :nodoc: all
View
46 test/test_rdoc_parser_ruby.rb
@@ -487,9 +487,55 @@ def test_parse_statements_identifier_alias_method
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
+ foo = @top_level.classes.first.method_list[0]
+ assert_equal 'foo', foo.name
+
foo2 = @top_level.classes.first.method_list.last
assert_equal 'foo2', foo2.name
assert_equal 'foo', foo2.is_alias_for.name
+ assert @top_level.classes.first.aliases.empty?
+ end
+
+ def test_parse_statements_identifier_alias_method_before_original_method
+ # This is not strictly legal Ruby code, but it simulates finding an alias
+ # for a method before finding the original method, which might happen
+ # to rdoc if the alias is in a different file than the original method
+ # and rdoc processes the alias' file first.
+ content = <<-EOF
+class Foo
+ alias_method :foo2, :foo
+
+ alias_method :foo3, :foo
+
+ def foo()
+ end
+
+ alias_method :foo4, :foo
+
+ alias_method :foo5, :unknown
+end
+EOF
+
+ util_parser content
+
+ @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
+
+ foo = @top_level.classes.first.method_list[0]
+ assert_equal 'foo', foo.name
+
+ foo2 = @top_level.classes.first.method_list[1]
+ assert_equal 'foo2', foo2.name
+ assert_equal 'foo', foo2.is_alias_for.name
+
+ foo3 = @top_level.classes.first.method_list[2]
+ assert_equal 'foo3', foo3.name
+ assert_equal 'foo', foo3.is_alias_for.name
+
+ foo4 = @top_level.classes.first.method_list.last
+ assert_equal 'foo4', foo4.name
+ assert_equal 'foo', foo4.is_alias_for.name
+
+ assert_equal @top_level.classes.first.aliases[0].old_name, "unknown"
end
def test_parse_statements_identifier_attr
Please sign in to comment.
Something went wrong with that request. Please try again.