Skip to content

Commit

Permalink
Run verifier on inherited attributes list
Browse files Browse the repository at this point in the history
Backports lsegal#432 referencing lsegal#467

Conflicts:

	templates/default/module/html/inherited_attributes.erb
  • Loading branch information
lsegal committed Jan 19, 2012
1 parent 372cd66 commit 115fc6b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion spec/templates/examples/module001.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collap


<h3 class="inherited">Attributes included from BaseMod</h3>
<p class="inherited">base_attr1, base_attr2, base_attr3</p>
<p class="inherited">#base_attr1, #base_attr2, #base_attr3</p>



Expand Down
12 changes: 6 additions & 6 deletions spec/templates/examples/module003.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ <h2>Instance Attribute Details</h2>
<pre class="lines">


8
9
10</pre>
10
11
12</pre>
</td>
<td>
<pre class="code"><span class="info file"># File '(stdin)', line 8</span>
<pre class="code"><span class="info file"># File '(stdin)', line 10</span>

def bar
@bar
Expand Down Expand Up @@ -166,10 +166,10 @@ <h2>Instance Method Details</h2>
<pre class="lines">


7</pre>
9</pre>
</td>
<td>
<pre class="code"><span class="info file"># File '(stdin)', line 7</span>
<pre class="code"><span class="info file"># File '(stdin)', line 9</span>

def foo; end</pre>
</td>
Expand Down
7 changes: 5 additions & 2 deletions spec/templates/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ def self.baz; end
html_equals(Registry.at('A').format(:format => :html, :no_highlight => true), :module002)
end

it "should ignore overwritten attributes from inherited list" do
it "should ignore overwritten/private attributes from inherited list" do
Registry.clear
YARD.parse_string <<-'eof'
module B
attr_reader :foo
attr_accessor :bar
# @private
attr_writer :baz
end
module A
include B
Expand All @@ -121,6 +123,7 @@ def foo; end
end
eof

html_equals(Registry.at('A').format(:format => :html, :no_highlight => true), :module003)
html_equals(Registry.at('A').format(:format => :html, :no_highlight => true,
:verifier => Verifier.new('!@private')), :module003)
end
end
16 changes: 6 additions & 10 deletions templates/default/module/html/inherited_attributes.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<% found_method = false %>
<% object.inheritance_tree(true)[1..-1].each do |superclass| %>
<% next if superclass.is_a?(YARD::CodeObjects::Proxy) %>
<% attribs = superclass.attributes[:instance] %>
<% attribs = attribs.reject {|name,rw| object.child(:scope => :instance, :name => name) != nil } %>
<% next if attribs.size == 0 %>
<% inherited_attr_list do |superclass, attribs| %>
<% if attr_listing.size == 0 && !found_method %><h2>Instance Attribute Summary</h2><% end %>
<% found_method = true %>
<h3 class="inherited">Attributes <%= superclass.type == :class ? 'inherited' : 'included' %> from <%= linkify superclass %></h3>
<p class="inherited"><%=
attribs.sort_by {|args| args.first.to_s }.collect do |args|
name, methods = args
method = methods[:read] || methods[:write]
name = method.name.to_s.gsub(/^#/,'') if superclass.type == :module && object.class_mixins.include?(superclass)
<p class="inherited"><%= attribs.map do |method|
name = method.name(true).gsub(/=$/, '')
if superclass.type == :module && object.instance_mixins.include?(superclass)
name = "##{name}" unless name =~ /^#/
end
linkify(method, name)
end.join(", ")
%></p>
Expand Down
11 changes: 11 additions & 0 deletions templates/default/module/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ def sort_listing(list)
list.sort_by {|o| [o.scope.to_s, o.name.to_s.downcase] }
end

def inherited_attr_list(&block)
object.inheritance_tree(true)[1..-1].each do |superclass|
next if superclass.is_a?(YARD::CodeObjects::Proxy)
attribs = superclass.attributes[:instance]
attribs = attribs.reject {|name, rw| object.child(:scope => :instance, :name => name) != nil }
attribs = attribs.sort_by {|args| args.first.to_s }.map {|n, m| m[:read] || m[:write] }
attribs = prune_method_listing(attribs, false)
yield superclass, attribs if attribs.size > 0
end
end

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

0 comments on commit 115fc6b

Please sign in to comment.