Extracting Code Statistics from rails
Switch branches/tags
Clone or download
bf4 Merge pull request #11 from rrrene/patch-2
Update docs badge in README
Latest commit 115cb53 Jun 22, 2014


CodeMetrics Inline docs

Independent library extracted from Rails code statistics.

Getting Started

  1. Install at the command prompt if you haven't yet:

    gem install code_metrics


  • Lines of code statistics for a folder

    • Command-line

    • As rake task

      require 'code_metrics/statistics'
      rake code_metrics:stats
      # or in Rails (check `rake -W stats` to see what tasks are loading)
      rake stats
    • As a library

      require 'code_metrics/code_statistics'
      dirs = CodeMetrics::StatsDirectories.new
      dirs.add_test_directories('spec/**/*_spec.rb', 'spec') # where the 2nd argument is a required string in the filename
      dirs.add_directories('engines/**/*.rb') # no restrictions on the file name, 2nd argument omitted
      dirs.add_test_directory('Acceptance specs', 'spec/acceptance')
      dirs.directories # outputs an array of [description, folder_path] to run statistics against
      # in Rails
      require 'rails/code_statistics'
        'Acceptance' => 'spec/acceptance',
      }.each do |type, dir|
        ::STATS_DIRECTORIES << ["#{name} specs", dir]
        ::CodeStatistics::TEST_TYPES << "#{name} specs"
  • Lines of code statistics for a list of files

    • As rake task

      require 'code_metrics/line_statistics'
      rake code_metrics:line_statistics[file_pattern] # e.g. ['lib/**/*.rb']
    • As a library

      require 'code_metrics/line_statistics'
      files = FileList["lib/active_record/**/*.rb"]
  • Profiling memory usage of requires. POSIX-only. Requires ps

    • Command-line

      code_metrics-profile <path/to/rubyfile.rb> [optional: ruby-prof mode]


Code Status

  • Build Status
  • Dependencies


Released under the MIT License.

Bitdeli Badge