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.

4

2 回答 2

3

你应该更喜欢你的源代码控制系统来跟踪谁写了什么。 git blame例如,可以生成一个带注释的列表,显示作者和源代码行。

识别视图应该很容易,它们位于视图目录中。静态方法定义通常可以使用 regexp 找到/\bdef\s+(?:\w+\.)?(\w+)\b/。将“动作”与其他方法区分开来可能涉及根据常见动作名称和通过检查路由发现的其他名称过滤方法名称。

于 2013-04-30T20:50:25.450 回答
1

与其重新发明轮子,不如使用现成的工具。如果你没有想到如何实现这样的代码,那么你可能无法编写这样的代码。像YARD这样的文档工具可能很有用。它的工作方式是在方法定义之前添加解释作为注释。通常这是用于编写供用户阅读的文档,但您可以偏离其预期用途并编写诸如程序员姓名或您喜欢的任何其他信息之类的内容。

于 2013-04-30T20:26:00.263 回答