I've been playing with flog lately, its a pretty good
tool to generate reports on code complexity for ruby applications. As a result of running
flog on a project codebase you get an output that looks similar to this:
1272.3: flog total
7.3: flog/method average
62.2: MyClass#foobar lib/myclass#foobar:123
... more similar lines ...
Example above provides a score for a method and references exact line number in the source code where that method is defined. This could be a regular instance/class method or any other "dynamic" method, eg. rake task and such.
So the objective is to extract a snippet of code (most likely a method) from source
file that starts with a line number defined in flog output. That snippet then could
be used in some web UI to show various code metrics (based on other tools like flay)
and/or stored in the database. As far as i can see, this task involves parsing ruby
code into AST, and then going through the tree to find corresponding start line and
figuring out end line number. I've done some experiments with this library - https://github.com/whitequark/parser, works most of the time, but it's a bit tricky to
get a correct result.
Are there any other solutions to quickly extract a method code from a source file written in ruby?