如何将annotate gem的Yard格式注释移至命名空间模型类前?
解决Annotate Gem在命名空间模型中注释位置的问题
要让Yard格式的Schema注释自动放在命名空间内的类定义前,只需调整Annotate的配置:
生成配置文件(若尚未创建):
bundle exec annotate --generate-config修改
.annotate.yml配置:
在配置文件中添加或修改以下两项:position_in_class: before annotate_nested_classes: true重新执行注释命令:
bundle exec annotate --models -f yard
修改后生成的代码会变成这样:
# frozen_string_literal: true module A # == Schema Information # # Table name: a_bs # # @!attribute id # @return [] # @!attribute date # @return [Date] # @!attribute created_at # @return [Time] # @!attribute updated_at # @return [Time] class B < ApplicationRecord end end
此时Yard就能正确识别该注释为A::B类的描述信息。如果不想全局配置,也可以直接在命令行追加参数:
bundle exec annotate --models -f yard --position-in-class before --annotate-nested-classes
内容的提问来源于stack exchange,提问作者Lars Schirrmeister
相关产品推荐
相关产品推荐

