Skip to content

Simple way to get basic code metrics in Ruby on Rails

I recently discovered the handy rake stats command! It gives you the following metrics:

  • lines of code
  • lines of test code
  • number of classes
  • number of methods
  • ratio of methods to classes
  • ratio of lines of code per method
  • You end up getting output like the following:

    +----------------------+--------+--------+---------+---------+-----+-------+
    | Name                 |  Lines |    LOC | Classes | Methods | M/C | LOC/M |
    +----------------------+--------+--------+---------+---------+-----+-------+
    | Controllers          |    108 |     91 |       6 |      15 |   2 |     4 |
    | Jobs                 |      2 |      2 |       1 |       0 |   0 |     0 |
    | Models               |    215 |    169 |      13 |      33 |   2 |     3 |
    | Mailers              |      4 |      4 |       1 |       0 |   0 |     0 |
    | Channels             |      8 |      8 |       2 |       0 |   0 |     0 |
    | Libraries            |    469 |    390 |      24 |      69 |   2 |     3 |
    | Controller tests     |      0 |      0 |       0 |       0 |   0 |     0 |
    | Model tests          |      0 |      0 |       0 |       0 |   0 |     0 |
    | Mailer tests         |      0 |      0 |       0 |       0 |   0 |     0 |
    | Integration tests    |      0 |      0 |       0 |       0 |   0 |     0 |
    | Model specs          |     76 |     60 |       0 |       0 |   0 |     0 |
    | Lib specs            |     21 |     18 |       0 |       0 |   0 |     0 |
    | Service specs        |    146 |    103 |       0 |       0 |   0 |     0 |
    | Integration specs    |    295 |    239 |       0 |       0 |   0 |     0 |
    +----------------------+--------+--------+---------+---------+-----+-------+
    | Total                |   1344 |   1084 |      47 |     117 |   2 |     7 |
    +----------------------+--------+--------+---------+---------+-----+-------+
      Code LOC: 664     Test LOC: 420     Code to Test Ratio: 1:0.6
    
    

    Published inRubyRuby on Rails

    Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *