diff --git a/spec/templates/module_spec.rb b/spec/templates/module_spec.rb index 416008249..16dbd095d 100644 --- a/spec/templates/module_spec.rb +++ b/spec/templates/module_spec.rb @@ -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[/(

\s*DSL Methods.*?)

/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 diff --git a/templates/default/module/html/inherited_methods.erb b/templates/default/module/html/inherited_methods.erb index 7d13ce46e..885ba4fd2 100644 --- a/templates/default/module/html/inherited_methods.erb +++ b/templates/default/module/html/inherited_methods.erb @@ -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 %>

Method Summary

<% end %> <% found_method = true %> diff --git a/templates/default/module/html/method_summary.erb b/templates/default/module/html/method_summary.erb index c05c4ee9a..4bbdb1163 100644 --- a/templates/default/module/html/method_summary.erb +++ b/templates/default/module/html/method_summary.erb @@ -10,5 +10,13 @@ <%= yieldall :item => meth %> <% end %> + <% (inherited_methods_by_group[name] || {}).each do |superclass, meths| %> +

Methods <%= superclass.type == :class ? 'inherited' : 'included' %> from <%= linkify superclass %>

+

<%= 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(", ") %>

+ <% end %> <% end %> <% end %> \ No newline at end of file diff --git a/templates/default/module/setup.rb b/templates/default/module/setup.rb index 95bf3a4bb..a1647ac88 100644 --- a/templates/default/module/setup.rb +++ b/templates/default/module/setup.rb @@ -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