如何使Yard` @ macro`s适用于多个文件

如果我在一个文件中有以下内容:

module Something class Resource # Defines a new property # @param [String] name the property name # @param [Class] type the property's type # @macro [attach] property # @return [$2] the $1 property def self.property(name, type) end end class Post < Resource property :title, String property :view_count, Integer end end 

使用get文档定义的methods property 。 但是,如果我在单独的文件中有这些定义,则文档生成不正确,例如在下面的情况中:

file0.rb

 require 'file1.rb' require 'file2.rb' 

file1.rb

 module Something class Resource # Defines a new property # @param [String] name the property name # @param [Class] type the property's type # @macro [attach] property # @return [$2] the $1 property def self.property(name, type) end end end 

file2.rb

 module Something class Post < Resource property :title, String property :view_count, Integer end end 

在单独的文件中, Yard宏在生成文档时不会inheritance。 如何实现这一目标?

YARD不遵循require调用,它也是单通道解析器,这意味着解析顺序很重要。 基本上,定义宏的文件必须在使用它的文件之前进行解析。 据推测,您的文件实际上并未命名为“file1.rb”和“file2.rb”,否则默认的glob排序可能对您有利。

要处理多个文件,只需确保YARD首先解析您的“file1.rb”。 您可以将它放在glob的前面,如下所示:

 $ yard doc lib/path/to/file1.rb lib/**/*.rb 

(“但是它会两次列出’file1.rb’,”你说?不要担心列表的统一,YARD会为你做这件事)