github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

rails / rails

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 4,955
    • 827
  • Source
  • Commits
  • Network (827)
  • Downloads (61)
  • Wiki (4)
  • Graphs
  • Tree: 85f2f34

click here to add a description

click here to add a homepage

  • Branches (6)
    • 1-2-stable
    • 2-0-stable
    • 2-1-stable
    • 2-2-stable
    • 2-3-stable
    • master
  • Tags (61)
    • v3.0.0.beta1
    • v2.3.5
    • v2.3.4
    • v2.3.3.1
    • v2.3.3
    • v2.3.2.1
    • v2.3.2
    • v2.3.1
    • v2.3.0
    • v2.2.3
    • v2.2.2
    • v2.2.1
    • v2.2.0
    • v2.1.2
    • v2.1.1
    • v2.1.0_RC1
    • v2.1.0
    • v2.0.5
    • v2.0.4
    • v2.0.3
    • v2.0.2
    • v2.0.1
    • v2.0.0_RC2
    • v2.0.0_RC1
    • v2.0.0_PR
    • v2.0.0
    • v1.2.6
    • v1.2.5
    • v1.2.4
    • v1.2.3
    • v1.2.2
    • v1.2.1
    • v1.2.0_RC2
    • v1.2.0_RC1
    • v1.2.0
    • v1.1.6
    • v1.1.5
    • v1.1.4
    • v1.1.3
    • v1.1.2
    • v1.1.1
    • v1.1.0_RC1
    • v1.1.0
    • v1.0.0
    • v0.14.4
    • v0.14.3
    • v0.14.2
    • v0.14.1
    • v0.13.1
    • v0.13.0
    • v0.12.0
    • v0.11.1
    • v0.11.0
    • v0.10.1
    • v0.10.0
    • v0.9.5
    • v0.9.4.1
    • v0.9.4
    • v0.9.3
    • v0.9.2
    • v0.9.1
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Ruby on Rails — Read more

  cancel

http://rubyonrails.org

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Remove a stray process2 require 
Yehuda Katz + Carl Lerche (author)
Tue Jun 16 16:29:33 -0700 2009
commit  85f2f34d5ec8ccdea4755740b810ac514d9f3dd9
tree    6527f995b5e3c6a7b471b677f708b548425d374b
parent  315147fcb5be2a937dcceb785de04a97616c49d0
rails / railties / lib / code_statistics.rb railties/lib/code_statistics.rb
100644 108 lines (85 sloc) 3.218 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
class CodeStatistics #:nodoc:
 
  TEST_TYPES = %w(Units Functionals Unit\ tests Functional\ tests Integration\ tests)
 
  def initialize(*pairs)
    @pairs = pairs
    @statistics = calculate_statistics
    @total = calculate_total if pairs.length > 1
  end
 
  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
 
  private
    def calculate_statistics
      @pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
    end
 
    def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
      stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
 
      Dir.foreach(directory) do |file_name|
        if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
          newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
          stats.each { |k, v| stats[k] += newstats[k] }
        end
 
        next unless file_name =~ pattern
 
        f = File.open(directory + "/" + file_name)
 
        while line = f.gets
          stats["lines"] += 1
          stats["classes"] += 1 if line =~ /class [A-Z]/
          stats["methods"] += 1 if line =~ /def [a-z]/
          stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
        end
      end
 
      stats
    end
 
    def calculate_total
      total = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
      @statistics.each_value { |pair| pair.each { |k, v| total[k] += v } }
      total
    end
 
    def calculate_code
      code_loc = 0
      @statistics.each { |k, v| code_loc += v['codelines'] unless TEST_TYPES.include? k }
      code_loc
    end
 
    def calculate_tests
      test_loc = 0
      @statistics.each { |k, v| test_loc += v['codelines'] if TEST_TYPES.include? k }
      test_loc
    end
 
    def print_header
      print_splitter
      puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |"
      print_splitter
    end
 
    def print_splitter
      puts "+----------------------+-------+-------+---------+---------+-----+-------+"
    end
 
    def print_line(name, statistics)
      m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0
      loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0
 
      start = if TEST_TYPES.include? name
        "| #{name.ljust(20)} "
      else
        "| #{name.ljust(20)} "
      end
 
      puts start +
           "| #{statistics["lines"].to_s.rjust(5)} " +
           "| #{statistics["codelines"].to_s.rjust(5)} " +
           "| #{statistics["classes"].to_s.rjust(7)} " +
           "| #{statistics["methods"].to_s.rjust(7)} " +
           "| #{m_over_c.to_s.rjust(3)} " +
           "| #{loc_over_m.to_s.rjust(5)} |"
    end
 
    def print_code_test_stats
      code = calculate_code
      tests = calculate_tests
 
      puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
      puts ""
    end
  end
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server