Skip to content

Support aliased-method #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions lib/rdoc/ri/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
39 changes: 38 additions & 1 deletion test/test_rdoc_ri_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -406,6 +432,7 @@ def test_classes
'Foo::Bar' => [@store1],
'Foo::Baz' => [@store1, @store2],
'Inc' => [@store1],
'Qux' => [@store1],
}

classes = @driver.classes
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down