Class: Rails::CodeStatistics

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/code_statistics.rb

Constant Summary collapse

DIRECTORIES =
[
%w(Controllers        app/controllers),
%w(Helpers            app/helpers),
%w(Jobs               app/jobs),
%w(Models             app/models),
%w(Mailers            app/mailers),
%w(Mailboxes          app/mailboxes),
%w(Channels           app/channels),
%w(Views              app/views),
%w(JavaScripts        app/assets/javascripts),
%w(Stylesheets        app/assets/stylesheets),
%w(JavaScript         app/javascript),
%w(Libraries          lib/),
%w(APIs               app/apis),
%w(Controller\ tests  test/controllers),
%w(Helper\ tests      test/helpers),
%w(Job\ tests         test/jobs),
%w(Model\ tests       test/models),
%w(Mailer\ tests      test/mailers),
%w(Mailbox\ tests     test/mailboxes),
%w(Channel\ tests     test/channels),
%w(Integration\ tests test/integration),
%w(System\ tests      test/system),
TEST_TYPES =
["Controller tests",
"Helper tests",
"Model tests",
"Mailer tests",
"Mailbox tests",
"Channel tests",
"Job tests",
"Integration tests",
"System tests"]
HEADERS =
{ lines: " Lines", code_lines: "   LOC", classes: "Classes", methods: "Methods" }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*pairs) ⇒ CodeStatistics

Returns a new instance of CodeStatistics.



60
61
62
63
64
# File 'lib/rails/code_statistics.rb', line 60

def initialize(*pairs)
  @pairs      = pairs
  @statistics = calculate_statistics
  @total      = calculate_total if pairs.length > 1
end

Class Method Details

.register_directory(label, path, test_directory: false) ⇒ Object

Add directories to the output of the ‘bin/rails stats` command.

Rails::CodeStatistics.register_directory("My Directory", "path/to/dir")

For directories that contain test code, set the ‘test_directory` argument to true.

Rails::CodeStatistics.register_directory("Model specs", "spec/models", test_directory: true)


55
56
57
58
# File 'lib/rails/code_statistics.rb', line 55

def self.register_directory(label, path, test_directory: false)
  self.directories << [label, path]
  self.test_types << label if test_directory
end

Instance Method Details

#to_sObject



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rails/code_statistics.rb', line 66

def to_s
  print_header
  @pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
  print_splitter

  if @total
    print_line("Total", @total)
    print_splitter
  end

  print_code_test_stats
end