Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Yard to document rails enum type

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.

like image 397
Favourite Onwuemene Avatar asked Oct 31 '15 16:10

Favourite Onwuemene


2 Answers

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:

like image 98
Tema Bolshakov Avatar answered Sep 20 '22 05:09

Tema Bolshakov


class User < ActiveRecord::Base

  # @attr [Enumerable<Symbol>] status
  enum status [:registering, :active, :suspended, :deleted]
end
like image 36
John Pollard Avatar answered Sep 21 '22 05:09

John Pollard