Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top