From 3fbf39cbc2f47d46e9b33342ec917375db41632f Mon Sep 17 00:00:00 2001 From: aycabta Date: Thu, 25 Jan 2018 18:49:12 +0900 Subject: [PATCH] Support aliased-method --- lib/rdoc/ri/driver.rb | 28 +++++++++++++++++++++----- test/test_rdoc_ri_driver.rb | 39 ++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb index cc36cd3dcb..c4d1dd03df 100644 --- a/lib/rdoc/ri/driver.rb +++ b/lib/rdoc/ri/driver.rb @@ -1443,7 +1443,13 @@ def render_method out, store, method, name # :nodoc: render_method_arguments out, method.arglists render_method_superclass out, method - render_method_comment out, method + if method.is_alias_for + al = method.is_alias_for + alias_for = store.load_method al.parent_name, "#{al.name_prefix}#{al.name}" + render_method_comment out, method, alias_for + else + render_method_comment out, method + end end def render_method_arguments out, arglists # :nodoc: @@ -1455,10 +1461,22 @@ def render_method_arguments out, arglists # :nodoc: out << RDoc::Markup::Rule.new(1) end - def render_method_comment out, method # :nodoc: - out << RDoc::Markup::BlankLine.new - out << method.comment - out << RDoc::Markup::BlankLine.new + def render_method_comment out, method, alias_for = nil# :nodoc: + if alias_for + unless method.comment.nil? or method.comment.empty? + out << RDoc::Markup::BlankLine.new + out << method.comment + end + out << RDoc::Markup::BlankLine.new + out << RDoc::Markup::Paragraph.new("(this method is alias for #{alias_for.full_name})") + out << RDoc::Markup::BlankLine.new + out << alias_for.comment + out << RDoc::Markup::BlankLine.new + else + out << RDoc::Markup::BlankLine.new + out << method.comment + out << RDoc::Markup::BlankLine.new + end end def render_method_superclass out, method # :nodoc: diff --git a/test/test_rdoc_ri_driver.rb b/test/test_rdoc_ri_driver.rb index 758c867b08..efbf087c61 100644 --- a/test/test_rdoc_ri_driver.rb +++ b/test/test_rdoc_ri_driver.rb @@ -243,6 +243,32 @@ def test_add_method assert_equal expected, out end + def test_add_method_that_is_alias_for_original + util_store + + out = doc + + @driver.add_method out, 'Qux#aliased' + + expected = + doc( + head(1, 'Qux#aliased'), + blank_line, + para('(from ~/.rdoc)'), + rule(1), + blank_line, + para('alias comment'), + blank_line, + blank_line, + para('(this method is alias for Qux#original)'), + blank_line, + para('original comment'), + blank_line, + blank_line) + + assert_equal expected, out + end + def test_add_method_attribute util_store @@ -406,6 +432,7 @@ def test_classes 'Foo::Bar' => [@store1], 'Foo::Baz' => [@store1, @store2], 'Inc' => [@store1], + 'Qux' => [@store1], } classes = @driver.classes @@ -939,6 +966,7 @@ def test_find_methods_method [@store1, 'Foo::Bar', 'Foo::Bar', :both, 'blah'], [@store1, 'Foo::Baz', 'Foo::Baz', :both, 'blah'], [@store1, 'Inc', 'Inc', :both, 'blah'], + [@store1, 'Qux', 'Qux', :both, 'blah'], ] assert_equal expected, items @@ -1072,7 +1100,7 @@ def test_list_known_classes @driver.list_known_classes end - assert_equal "Ambiguous\nExt\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out + assert_equal "Ambiguous\nExt\nFoo\nFoo::Bar\nFoo::Baz\nInc\nQux\n", out end def test_list_known_classes_name @@ -1497,6 +1525,15 @@ def util_store @overridden.comment = 'must not be displayed in Bar#override' @overridden.record_location @top_level + @cQux = @top_level.add_class RDoc::NormalClass, 'Qux' + + @original = @cQux.add_method RDoc::AnyMethod.new(nil, 'original') + @original.comment = 'original comment' + @original.record_location @top_level + + @aliased = @original.add_alias RDoc::Alias.new(nil, 'original', 'aliased', 'alias comment'), @cQux + @aliased.record_location @top_level + @store1.save @driver.stores = [@store1]