Documenting def_delegators with Yardoc

I have a class that uses the def_delegators method from the Forwardable module. I did not find a way to get Yardoc to output documentation for it. I tried using macro , but it does not output anything for these specific methods (everything else in the file is fine and there are no errors), and I have several def_delegators different lengths.

eg.

 class A extend Forwardable # other code… # @!macro # @see Array#$1 # @see Array#$2 # @see Array#$3 def_delegators :@xs, :size, :<<, :blah # … 

If anyone knows about a gem or a way to do this, it means that I can avoid trying to write a Yard extension for this, I would be very grateful.

+8
ruby documentation yard
source share
3 answers

After several experiments, I found that it worked quite well:

  # @!method size # @see Array#size # @!method << # @see Array#<< # @!method blah # @see Array#blah def_delegators :@xs, :size, :<<, :blah # … 

It is possible that this can be done in one or two lines, but compared to the work written on the extension, I find this very acceptable.


Update:

I just found that a link to documentation with delegated methods would be better:

  # @!method size # @return (see Array#size) 

This will take the already registered return value from the # array size method. I expect other tags to do this too. This is still quite verbose, but acceptable.

+3
source share

You need to combine two concepts. Use the @ macro! To create the @! Method.

Below is my version of the solution. But the problem for me is OptParser, which is not included, so See also has no link. The second drawback is the method signature, parameters and return value are not described. And the third ick is the OptParser line, but it really can be configured (parameterized).

If he forwarded the method included in the project, you could use (see the Foo # method) (in this case there is no @ sign), and everything that is in the Foo # method will be copied to a new source. This can be done by executing (see Foo # $ 2) inside the macro - with the guy turned on. See YARD Reference Tags

 # @!macro [attach] def_delegators # @!method $2 # Forwards to $1. # @see OptParser#$2 def_delegators :opt_parser, :order! def_delegators :opt_parser, :on def_delegators :opt_parser, :on_head def_delegators :opt_parser, :on_tail def_delegators :opt_parser, :help def_delegators :opt_parser, :add_officious def_delegators :opt_parser, :banner def_delegators :opt_parser, :banner= def_delegators :opt_parser, :program_name def_delegators :opt_parser, :abort def_delegators :opt_parser, :release def_delegators :opt_parser, :release= def_delegators :opt_parser, :version def_delegators :opt_parser, :version= 
0
source share

This works for me.

 # @!method do_this # @return [mixed] See {Instance#do_this}. # @!method do_that # @return [mixed] See {Instance#do_that}. delegate *[ :do_this, :do_that, ], to: :instance 

Other:

  • gem yard-delegate does not work for such a design. It is quite old though.
  • The premise # @!method higher than the individual :method does not work (ignored by YARD).
  • It is better to indicate the actual return value of the method, it creates a list that is more convenient for the reader.
0
source share

All Articles