0

I'm starting a project with several contributors. We want to keep track of who wrote what code, as well as to get a count of how many methods, controller actions, and views a contributor has written. This necessitates a level of meta-programming that none of us are familiar with.

So far, the best idea we've come up with is to add a comment before each snippet of code with the contributor's username and a short, consistent phrase. For instance:

# method by RacerX
def a_useful_method
  . . .
end

# method by MysteryProgrammer123
def another_useful_method
  . . .
end

# action by MysteryProgrammer123
def new
  . . .
end

Then we'd run a method to count all instances of action by and method by and view by that each user has written throughout the project. Unfortunately, we don't know how to write Ruby code that can inspect other Ruby code. It might not even be possible. If it is possible, though, how is it done?

Alternatively, there might be a better approach that we're not considering.

2
  • 4
    How will you count a method written by one person and changed by another? I'd try mining the output of git blame rather than relying on people to annotate the code they've written Commented Apr 30, 2013 at 20:18
  • This is a super bad idea. Having a program produce metrics about itself is totally wrong-headed. Use Git or any other VCS and throw out the meta-code and comment markup. Commented Apr 30, 2013 at 20:59

2 Answers 2

3

You should prefer your source control system to track who wrote what. git blame, for instance, can produce an annotated listing showing author and source line.

Identifying views should be easy, they're in the view directory. Static method definitions can generally be found with regexp /\bdef\s+(?:\w+\.)?(\w+)\b/. Distinguishing "actions" from other methods probably involves filtering method names against common action names and other names discovered by examining your routes.

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent. This simplifies things greatly.
1

Rather than reinventing the wheel, use a ready-made tool. And if it does not come to your mind how to implement such code, then you probably will not be able to write such code. A documentation tool such as YARD may be useful. The way this works is that you add explanations as comments before method definitions. Usually this is for writing the documentation to be read by the users, but you can depart from its intended use and write things like the programmers name, or whatever other information you like.

2 Comments

Thanks for letting me know about YARD. I'm going to go with git blame on this one, but YARD will be a handy tool in the future.
Right. That's the way you should go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.