Skip to content
Extracting Code Statistics from rails
Ruby JavaScript CSS
Find file
Latest commit 115cb53 @bf4 Merge pull request #11 from rrrene/patch-2
Update docs badge in README
Failed to load latest commit information.
bin Remove duplication in executable code_metrics
lib Fix invalid bytes sequence crash, bump to 0.1.3
test Remove test database dependencies
.gitignore Remove Gemfile.lock from source control, update gitignore
.travis.yml Remove testing Ruby 1.9.2 as the current matrix require >=1.9.3 for R…
.yardopts Add yardopts
Gemfile Rename excluded gem group so travis will install development dependen…
MIT-LICENSE BF convert to working gem and rails plugin
Rakefile Allow rdoc rake task loading to fail
code_metrics.gemspec Update readme/gemspec to reflect Rails PR rejection

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 =
      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*dirs).to_s
      # 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

Something went wrong with that request. Please try again.