【问题标题】:How to use Yard to document rails enum type如何使用 Yard 记录 rails 枚举类型
【发布时间】:2016-01-31 22:03:13
【问题描述】:

我有一个类似这样的 ActiveRecord 类:

class User < ActiveRecord::Base

  # How do I document this?
  enum status [:registering, :active, :suspended, :deleted]
end

status 属性用于构建状态机。如何使用 yard 记录那行代码?文档需要包含对status 属性及其所有可能状态的解释。

【问题讨论】:

    标签: ruby-on-rails enums coding-style documentation yard


    【解决方案1】:
    class User < ActiveRecord::Base
    
      # @attr [Enumerable<Symbol>] status
      enum status [:registering, :active, :suspended, :deleted]
    end
    

    【讨论】:

      【解决方案2】:

      只需将所有选项以逗号分隔的列表形式列出。

      class User < ActiveRecord::Base
      
        # @!attribute [rw] status
        #   @return [:registering, :active, :suspended, :deleted]
        enum status [:registering, :active, :suspended, :deleted]
      end
      

      如果不确定类型定义,可以咨询YARD Type Parser

      【讨论】:

      • 赏金奖励给你没有更好的答案;)
      • 它返回字符串而不是符号。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      • 2011-07-17
      • 2014-04-10
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多