Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YARD: documenting class methods added by an included module

I am writing documentation for my ruby gem using YARD. In my gem, I have some code which follows this common ruby pattern where a module is included in a class, and that module not only adds instance methods but it also adds class methods:

module Moo
  def self.included(klass)
    klass.extend ClassMethods
  end

  module ClassMethods
    def hello
      puts "hello"
    end
  end
end

class Foo
  include Moo
end

Foo.hello  # => class method runs, printing "hello"

By default, YARD will generate documentation for the Foo class that looks like this:

Inadequate documentation of the Foo class

I think this documentation is inadequate because it does not tell the user that the Foo.hello method is available. To learn about hello, the user has to click on Moo and then click on ClassMethods.

It would be great to have a list of all the class and instance methods of Foo on one page. How can I make that happen? Do I need to change the code, or is there a tag I can add to give YARD a hint about ClassMethods?

like image 621
David Grayson Avatar asked Jan 15 '12 20:01

David Grayson


1 Answers

Since v0.8.0 you can use the @!parse directive:

class Foo
  include Moo
  # @!parse extend Moo::ClassMethods
end
like image 159
tmatilai Avatar answered Oct 21 '22 07:10

tmatilai