code_statistics 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{code_statistics}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Mayer"]
12
- s.date = %q{2009-10-27}
12
+ s.date = %q{2009-10-28}
13
13
  s.description = %q{"This is a port of the rails 'rake stats' method so it can be made more robust and work for non rails projects. New features may eventually be added as well."}
14
14
  s.email = %q{dan@devver.net}
15
15
  s.extra_rdoc_files = [
@@ -3,10 +3,12 @@ module CodeStatistics
3
3
 
4
4
  TEST_TYPES = %w(Units Functionals Unit\ tests Functional\ tests Integration\ tests)
5
5
 
6
+
6
7
  def initialize(*pairs)
7
- @pairs = pairs
8
+ @pairs = pairs
8
9
  @statistics = calculate_statistics
9
- @total = calculate_total if pairs.length > 1
10
+ @total = calculate_total if pairs.length > 1
11
+ @test_types = []
10
12
  end
11
13
 
12
14
  def to_s
@@ -26,10 +28,31 @@ module CodeStatistics
26
28
  def calculate_statistics
27
29
  @pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
28
30
  end
31
+
32
+ def local_file_exists?(dir,filename)
33
+ File.exist?(File.join(dir,filename))
34
+ end
35
+
36
+ def test_types
37
+ (TEST_TYPES + @test_types).uniq
38
+ end
39
+
40
+ def add_test_type(test_type)
41
+ @test_types << test_type
42
+ end
29
43
 
30
44
  def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
31
45
  stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
32
46
 
47
+ add_test_type("Model specs") if local_file_exists?(directory, 'spec/models')
48
+ add_test_type("View specs") if local_file_exists?(directory, 'spec/views')
49
+ add_test_type("Controller specs") if local_file_exists?(directory, 'spec/controllers')
50
+ add_test_type("Helper specs") if local_file_exists?(directory, 'spec/helpers')
51
+ add_test_type("Library specs") if local_file_exists?(directory, 'spec/lib')
52
+ add_test_type("Routing specs") if local_file_exists?(directory, 'spec/routing')
53
+ add_test_type("Integration specs") if local_file_exists?(directory, 'spec/integration')
54
+ add_test_type("Specs") if if local_file_exists?(directory, 'spec')
55
+
33
56
  Dir.foreach(directory) do |file_name|
34
57
  if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
35
58
  newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
@@ -59,13 +82,13 @@ module CodeStatistics
59
82
 
60
83
  def calculate_code
61
84
  code_loc = 0
62
- @statistics.each { |k, v| code_loc += v['codelines'] unless TEST_TYPES.include? k }
85
+ @statistics.each { |k, v| code_loc += v['codelines'] unless test_types.include? k }
63
86
  code_loc
64
87
  end
65
88
 
66
89
  def calculate_tests
67
90
  test_loc = 0
68
- @statistics.each { |k, v| test_loc += v['codelines'] if TEST_TYPES.include? k }
91
+ @statistics.each { |k, v| test_loc += v['codelines'] if test_types.include? k }
69
92
  test_loc
70
93
  end
71
94
 
@@ -83,7 +106,7 @@ module CodeStatistics
83
106
  m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0
84
107
  loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0
85
108
 
86
- start = if TEST_TYPES.include? name
109
+ start = if test_types.include? name
87
110
  "| #{name.ljust(20)} "
88
111
  else
89
112
  "| #{name.ljust(20)} "
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-27 00:00:00 -04:00
12
+ date: 2009-10-28 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency