Skip to content
Open
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
34 changes: 34 additions & 0 deletions spec/templates/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,38 @@ module A
eof
html_equals(Registry.at('A').format(html_options), :module005)
end

it "shows inherited methods from matching groups in the group section, not in flat inherited section" do
Registry.clear
YARD.parse_string <<-'eof'
class Parent
# @group DSL Methods
def parent_dsl; end

# @group Other
def parent_other; end
end

class Child < Parent
# @group DSL Methods
def child_dsl; end
end
eof

result = Registry.at('Child').format(html_options)

# The "DSL Methods" section should contain an "inherited from Parent" subsection with parent_dsl
dsl_section = result[/(<h2>\s*DSL Methods.*?)<h2>/m, 1]
expect(dsl_section).not_to be_nil
expect(dsl_section).to include('inherited')
expect(dsl_section).to include('parent_dsl')

# parent_dsl should NOT appear outside the "DSL Methods" section
# i.e. it should not appear in the flat inherited section
rest_of_page = result.sub(dsl_section, '')
expect(rest_of_page).not_to include('parent_dsl')

# parent_other (in "Other" group, not in Child) should still appear in the flat inherited section
expect(result).to include('parent_other')
end
end
1 change: 1 addition & 0 deletions templates/default/module/html/inherited_methods.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<% meths = prune_method_listing(superclass.meths(:included => false, :inherited => false)) %>
<% meths.reject! {|m| object.child(:scope => m.scope, :name => m.name) != nil } %>
<% meths.reject! {|m| m.is_alias? || m.is_attribute? } %>
<% meths.reject! {|m| m.group && object.groups && object.groups.include?(m.group) } %>
<% next if meths.size == 0 %>
<% if method_listing.size == 0 && !found_method %><h2>Method Summary</h2><% end %>
<% found_method = true %>
Expand Down
8 changes: 8 additions & 0 deletions templates/default/module/html/method_summary.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@
<%= yieldall :item => meth %>
<% end %>
</ul>
<% (inherited_methods_by_group[name] || {}).each do |superclass, meths| %>
<h3 class="inherited">Methods <%= superclass.type == :class ? 'inherited' : 'included' %> from <%= linkify superclass %></h3>
<p class="inherited"><%= meths.sort_by {|o| o.name.to_s }.map {|m|
mname = m.name(true)
mname = mname.gsub(/^#/, '') if superclass.type == :module && object.class_mixins.include?(superclass)
linkify(m, mname)
}.join(", ") %></p>
<% end %>
<% end %>
<% end %>
20 changes: 20 additions & 0 deletions templates/default/module/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ def inherited_constant_list
end
end

def inherited_methods_by_group
return @inherited_meths_by_group if defined?(@inherited_meths_by_group)
@inherited_meths_by_group = {}
return @inherited_meths_by_group unless object.groups

object.inheritance_tree(true)[1..-1].each do |superclass|
next if superclass.is_a?(YARD::CodeObjects::Proxy)
next if options.embed_mixins.size > 0 && options.embed_mixins_match?(superclass) != false
meths = prune_method_listing(superclass.meths(:included => false, :inherited => false))
meths.reject! {|m| object.child(:scope => m.scope, :name => m.name) != nil }
meths.reject! {|m| m.is_alias? || m.is_attribute? }
meths.each do |m|
next unless m.group && object.groups.include?(m.group)
(@inherited_meths_by_group[m.group] ||= {})[superclass] ||= []
@inherited_meths_by_group[m.group][superclass] << m
end
end
@inherited_meths_by_group
end

def docstring_full(obj)
docstring = obj.tags(:overload).size == 1 && obj.docstring.empty? ?
obj.tag(:overload).docstring : obj.docstring
Expand Down