tag:rubydoc.tenderapp.com,2010-12-26:/discussions/suggestions/3-better-docs-for-cattr_-and-mattr_Rubydoc.info: Discussion 2018-10-19T03:09:08Ztag:rubydoc.tenderapp.com,2010-12-26:Comment/103569952011-10-02T14:47:47Z2011-10-02T14:50:31ZBetter docs for cattr_* and mattr_*?<div><p>If you packaged this up as a plugin and put the gem up on
rubygems.org we could install this on rubydoc.info and everybody
would win! Interested? :)</p>
<p>And yes, that handler looks like it would work just fine as is.
Of course any improvements could be made over time (release early /
often!), but it's a fine start.</p></div>lsegaltag:rubydoc.tenderapp.com,2010-12-26:Comment/103569952011-10-02T15:05:23Z2011-10-04T21:11:16ZBetter docs for cattr_* and mattr_*?<div><p>Let me see what I can do -- never released a gem before! But
you're right, this seems like a good time to give it a shot.</p>
<p>Am I right in reading the <code>AttributeHandler</code> code
that the read/write detection there won't work unless the
<code>c</code> and <code>m</code> are removed from the method name?
If so, what's the right way to do that? Can a handler just
<em>change</em> <code>statement.method_name</code>? If not, does
that mean one would have to swallow the <code>cattr_*</code> method
call, and create a new corresponding <code>attr_*</code> method
call that would then be picked up by
<code>AttributeHandler</code>?</p></div>deactivatedtag:rubydoc.tenderapp.com,2010-12-26:Comment/103569952011-10-02T16:31:34Z2011-10-02T16:31:34ZBetter docs for cattr_* and mattr_*?<div><p>Yes, you are correct that you would need to change the names.
You CAN forcibly rewrite the AST node (it's just an array object,
effectively), and this would probably be a reasonable hack until we
found a better way to do this. We should probably refactor the attr
handler to not hardcode those read write attribute method names,
that would be the best. Until then, you can rewrite the method name
and call super. The other way to do it would be to manually set the
object as writable after the object is created, but that's probably
uglier.</p></div>lsegaltag:rubydoc.tenderapp.com,2010-12-26:Comment/103569952011-10-02T20:31:44Z2011-10-04T21:11:16ZBetter docs for cattr_* and mattr_*?<div><p>This whole gem thing isn't as hard as I expected. <a href=
"yard-rails%200.1.0%20published%20here."></a><a href=
"https://rubygems.org/gems/yard-rails">https://rubygems.org/gems/yard-rails</a>
It comes with a small RSpec test suite, which currently only tests
<code>[c,m]attr_*</code> on both the 1.9 and the legacy 1.8
parser.</p>
<p><a href=
"https://github.com/cpence/yard-rails/blob/master/lib/yard-rails/class_attribute_handler.rb">
1.9-parser source is here</a>, and <a href=
"https://github.com/cpence/yard-rails/blob/master/lib/yard-rails/legacy/class_attribute_handler.rb">
1.8-parser source is here</a>. In both cases, I just clobber
<code>statement[0]</code> and replace it with the appropriate new
AST node/token text, which seems to work like a champ for now.</p></div>deactivatedtag:rubydoc.tenderapp.com,2010-12-26:Comment/103569952011-10-02T21:00:20Z2011-10-02T21:00:20ZBetter docs for cattr_* and mattr_*?<div><p>Awesome! Will get it installed soon. Just as a side note, have
you tried just doing a string mutation directly on the method name
object itself? Like .replace, or just replace the name element in
the ident node. Those would save you from recreating the node from
scratch, but I guess golfing a hack is kind of pointless...</p></div>lsegaltag:rubydoc.tenderapp.com,2010-12-26:Comment/103569952011-10-02T21:24:17Z2011-10-04T21:11:17ZBetter docs for cattr_* and mattr_*?<div><p>I had some funny results when trying to work on the ident node
itself, having to do with <code>source</code> and
<code>full_source</code> (changes getting overwritten in funny
ways). Par for the course for hacking into a parser you didn't
write yourself. =)</p></div>deactivatedtag:rubydoc.tenderapp.com,2010-12-26:Comment/103569952011-10-03T04:31:05Z2011-10-03T04:31:05ZBetter docs for cattr_* and mattr_*?<div><p>So I just installed it on the server-- you should now be able to
specify the plugin in your yardopts via <code>--plugin
rails</code></p></div>lsegaltag:rubydoc.tenderapp.com,2010-12-26:Comment/103569952011-10-04T20:58:38Z2011-10-04T20:58:39ZBetter docs for cattr_* and mattr_*?<div><p>I think I set this up right (<a href=
"https://github.com/cpence/rletters/blob/master/.yardopts">yardopts
file is here</a>), but I'm not seeing the updated docs. See the
docs for the Document class <a href=
"http://rubydoc.info/github/cpence/rletters/master/Document">here</a>.
When I run YARD locally with the plugin installed, I get the
following section, which is still absent on Rubydoc:</p>
<blockquote>
<p>Class Attribute Summary<br>
+ (Hash) facets readonly<br>
Faceted browsing information that was returned by the last
search.<br>
+ (Integer) num_results readonly<br>
Number of documents returned by the last search.</p>
</blockquote></div>deactivatedtag:rubydoc.tenderapp.com,2010-12-26:Comment/103569952011-10-19T03:42:56Z2011-10-19T03:42:56ZBetter docs for cattr_* and mattr_*?<div><p>Hey sorry for the late reply. Did you manage to get this
working? I'm seeing those class attributes showing up now. But it
might have been something I did on the server.</p></div>lsegaltag:rubydoc.tenderapp.com,2010-12-26:Comment/103569952011-10-19T11:41:38Z2011-10-19T11:41:38ZBetter docs for cattr_* and mattr_*?<div><p>Yep, seems like they're working now! You can close this one
up.</p></div>deactivated