How to use Yard to document rails enum type
Asked Answered
G

2

10

I have an ActiveRecord class similar to this:

class User < ActiveRecord::Base

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

status attribute is used to build a state machine. How do I document that line of code using yard? The documentation needs to contain explanation of status attribute and all it's possible states.

Gober answered 31/10, 2015 at 16:3 Comment(0)
A
8

Just list all options as comma separated list.

class User < ActiveRecord::Base

  # @!attribute [rw] status
  #   @return [:registering, :active, :suspended, :deleted]
  enum status [:registering, :active, :suspended, :deleted]
end

If you are not sure about type definition, you may consult with YARD Type Parser:

Abundant answered 8/11, 2015 at 19:3 Comment(2)
Bounty awarded to you for lack of a better answer ;)Gober
It returns string instead of symbol.Anzovin
E
6
class User < ActiveRecord::Base

  # @attr [Enumerable<Symbol>] status
  enum status [:registering, :active, :suspended, :deleted]
end
Electrophoresis answered 6/11, 2015 at 19:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.