Extracting Code Statistics from rails
Ruby JavaScript CSS
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
test
.gitignore
.travis.yml
.yardopts
Gemfile
HISTORY Fix invalid bytes sequence crash, bump to 0.1.3 Dec 31, 2013
MIT-LICENSE
README.md
Rakefile
code_metrics.gemspec

README.md

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

Usage

  • Lines of code statistics for a folder

    • Command-line

      code_metrics
    • 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
      CodeMetrics::Statistics.new(*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"
      end
      CodeStatistics.new(*STATS_DIRECTORIES).to_s
  • 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"]
      CodeMetrics::LineStatistics.new(files).print_loc
  • Profiling memory usage of requires. POSIX-only. Requires ps

    • Command-line

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

Contributing

Code Status

  • Build Status
  • Dependencies

License

Released under the MIT License.

Bitdeli Badge