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[/(
<%= 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