Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to best document value classes with yard? #45

Open
ms-ati opened this issue Sep 8, 2015 · 0 comments
Open

How to best document value classes with yard? #45

ms-ati opened this issue Sep 8, 2015 · 0 comments

Comments

@ms-ati
Copy link
Contributor

ms-ati commented Sep 8, 2015

I suggest that there should be a documented best practice for documenting value classes with yard.

Requirements:

  • Works on rubydoc.info for docs
  • Works in Rubymine for completion
  • Allows documenting the type(s) of each field

I've put a gist together showing how it currently works. As you can see, Example3 works about 75%, which I think is the best we can do at the moment.

So that leads me to a documentation proposal. What do you think of this:


How to Document a Value class using YARD

Current best practice for writing YARD documentation for value classes created with this gem can be best summed up as "make them look like Structs for YARD":

  1. Use the inheritance syntax (eg class A < Value.new(...)) rather than assigning to a constant
  2. Document each field using YARD tag @attr_reader (docs)
Example
# What is a person?
#
# @attr_reader [String]        name     Full name
# @attr_reader [Fixnum]        age      Age in years
# @attr_reader [Array<Person>] friends  List of friends
class Person < Value.new(:name, :age, :friends); end
Still TODO
  • tell YARD about generated constructor
  • tell YARD about generated class methods: .with
  • tell YARD about the generated instance methods: #==, #eql?, #values, #inspect, #with, #to_h, #to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant