code_stats2 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/code_stats +38 -20
- data/lib/code_stats.rb +3 -3
- data/lib/code_stats/code_stats.rb +19 -14
- data/lib/code_stats/file_set.rb +2 -2
- data/lib/code_stats/gems.rb +1 -1
- data/lib/code_stats/languages.rb +40 -40
- data/lib/code_stats/project.rb +17 -17
- data/lib/code_stats/report.rb +11 -11
- data/lib/code_stats/support.rb +1 -1
- data/readme.md +3 -3
- data/spec/code_stats_spec.rb +1 -1
- data/spec/languages_spec.rb +25 -25
- data/spec/project_spec.rb +7 -7
- data/spec/spec_helper.rb +4 -0
- metadata +10 -10
data/bin/code_stats
CHANGED
@@ -4,28 +4,46 @@ lib_dir = %(#{File.expand_path "#{__FILE__}/../.."}/lib)
|
|
4
4
|
$LOAD_PATH << lib_dir unless $LOAD_PATH.include? lib_dir
|
5
5
|
|
6
6
|
require 'code_stats'
|
7
|
+
require 'optparse'
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
options = {}
|
10
|
+
parser = OptionParser.new do |opts|
|
11
|
+
opts.banner = <<-TEXT
|
12
|
+
Language-agnostic Code Statistics
|
13
|
+
|
14
|
+
Usage:
|
15
|
+
$ code_stats /projects/wordpress /projects/drupal
|
16
|
+
$ code_stats /projects/*
|
17
|
+
$ code_stats /projects/wordpress --except JavaScript --skip /tmp/
|
11
18
|
|
12
|
-
Usage:
|
13
|
-
$ code_stats /projects/wordpress /projects/drupal
|
14
|
-
$ code_stats /projects/*
|
15
|
-
$ code_stats /projects/wordpress /projects/drupal except: JavaScript skip_filter: /tmp/
|
16
|
-
|
17
|
-
Options:
|
18
|
-
except: JavaScript - analyze all languages except JavaScript
|
19
|
-
only: Ruby - analyze Ruby language only
|
20
|
-
specs_filter: regex, specifies should be path threated as specs, default: #{CodeStats::Project::DEFAUL_SPEC_FILTER.source}
|
21
|
-
skip_filter: regex, specifies paths that should be skipped, default: #{CodeStats::Project::DEFAUL_SKIP_FILTER.source}
|
22
19
|
TEXT
|
23
|
-
|
24
|
-
|
20
|
+
|
21
|
+
opts.on("--except LANG", "Analyze all languages except specified.") do |lang|
|
22
|
+
(options[:except] ||= []) << lang.to_sym
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
options
|
28
|
-
|
29
|
-
|
25
|
+
opts.on("--only LANG", "Analyze only specified language(es).") do |lang|
|
26
|
+
(options[:only] ||= []) << lang.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on(
|
30
|
+
"--specs REGEX",
|
31
|
+
"Specify paths that should be threated as specs/tests (default #{CodeStats::Project::DEFAUL_SPEC_FILTER.source})."
|
32
|
+
) do |re|
|
33
|
+
options[:spec_filter] = Regexp.new(re)
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on(
|
37
|
+
"--skip REGEX",
|
38
|
+
"Specify paths that should be skipped (default #{CodeStats::Project::DEFAUL_SKIP_FILTER.source})."
|
39
|
+
) do |re|
|
40
|
+
options[:skip_filter] = Regexp.new(re)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
parser.parse!
|
30
44
|
|
31
|
-
|
45
|
+
if ARGV.empty?
|
46
|
+
puts parser.banner
|
47
|
+
else
|
48
|
+
CodeStats.analyze_and_report *(ARGV + [options])
|
49
|
+
end
|
data/lib/code_stats.rb
CHANGED
@@ -10,11 +10,11 @@ require 'tilt'
|
|
10
10
|
class CodeStats
|
11
11
|
class << self
|
12
12
|
def extensions; @extensions ||= {} end
|
13
|
-
|
13
|
+
|
14
14
|
attr_accessor :file_size_limit
|
15
|
-
attr_required :file_size_limit
|
15
|
+
attr_required :file_size_limit
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
self.file_size_limit = 500 * 1024
|
19
19
|
end
|
20
20
|
|
@@ -1,24 +1,24 @@
|
|
1
1
|
class CodeStats
|
2
|
-
class << self
|
2
|
+
class << self
|
3
3
|
def know? extension
|
4
4
|
extensions.include? extension
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def parse text, extension
|
8
8
|
language = extensions[extension] || raise("no language for :#{extension} extension!")
|
9
9
|
language.new text
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def analyze *args
|
13
13
|
options = args.extract_options!
|
14
|
-
paths = args
|
14
|
+
paths = args
|
15
15
|
paths.collect!{|path| Dir[path]}.flatten!
|
16
|
-
|
17
|
-
|
18
|
-
please wait, analyzing:
|
16
|
+
|
17
|
+
info <<-TEXT
|
18
|
+
please wait, analyzing following projects:
|
19
19
|
#{paths.join("\n ")}
|
20
20
|
TEXT
|
21
|
-
|
21
|
+
|
22
22
|
projects = paths.collect do |path|
|
23
23
|
project = Project.new path, options
|
24
24
|
project.analyze!
|
@@ -26,26 +26,31 @@ TEXT
|
|
26
26
|
end
|
27
27
|
projects.sort{|a, b| b.characters_count <=> a.characters_count}
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def analyze_and_report *args
|
31
31
|
# parsing options
|
32
32
|
options = args.extract_options!
|
33
33
|
paths = args
|
34
|
-
|
34
|
+
|
35
35
|
options.validate_options! *(FileSet::AVAILIABLE_OPTIONS + Project::AVAILIABLE_OPTIONS)
|
36
36
|
project_options = options.select{|k, v| Project::AVAILIABLE_OPTIONS.include? k}
|
37
37
|
lang_options = options.select{|k, v| FileSet::AVAILIABLE_OPTIONS.include? k}
|
38
|
-
|
38
|
+
|
39
39
|
# analyzing & reporting
|
40
40
|
projects = analyze *(paths << project_options)
|
41
41
|
report = Report.new(*(projects << lang_options)).render
|
42
|
-
|
42
|
+
|
43
43
|
report_file = "./projects_statistics.html".to_file
|
44
|
-
report_file.write
|
44
|
+
report_file.write report
|
45
45
|
|
46
|
-
|
46
|
+
info "done, statistics are in #{report_file}"
|
47
47
|
|
48
48
|
Kernel.exec "open #{report_file}"
|
49
49
|
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
def info msg
|
53
|
+
puts msg
|
54
|
+
end
|
50
55
|
end
|
51
56
|
end
|
data/lib/code_stats/file_set.rb
CHANGED
@@ -2,7 +2,7 @@ class CodeStats::FileSet
|
|
2
2
|
def initialize
|
3
3
|
@lines_count_by_language, @characters_count_by_language = Hash.new(0), Hash.new(0)
|
4
4
|
end
|
5
|
-
|
5
|
+
|
6
6
|
def lines_count options = {}
|
7
7
|
total_count = 0
|
8
8
|
lines_count_by_language(options).each{|lang, count| total_count += count}
|
@@ -27,7 +27,7 @@ class CodeStats::FileSet
|
|
27
27
|
@lines_count_by_language[script.class.alias.to_sym] += script.lines_count
|
28
28
|
@characters_count_by_language[script.class.alias.to_sym] += script.characters_count
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
AVAILIABLE_OPTIONS = [:only, :except]
|
32
32
|
|
33
33
|
protected
|
data/lib/code_stats/gems.rb
CHANGED
data/lib/code_stats/languages.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
module CodeStats::Languages
|
2
2
|
class Abstract
|
3
|
-
attr_reader :text
|
4
|
-
|
3
|
+
attr_reader :text
|
4
|
+
|
5
5
|
def initialize text
|
6
6
|
@text = text
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def self.extensions *args
|
10
10
|
if args.size > 0
|
11
11
|
@extensions = args
|
12
|
-
|
12
|
+
|
13
13
|
@extensions.each{|ext| CodeStats.extensions[ext] = self}
|
14
14
|
else
|
15
15
|
@extensions ||= []
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def lines_count
|
20
20
|
calculate_basic_statistics
|
21
21
|
@lines_count
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def characters_count
|
25
25
|
calculate_basic_statistics
|
26
26
|
@characters_count
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def analyze
|
30
30
|
calculate_basic_statistics
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
protected
|
34
34
|
def calculate_basic_statistics
|
35
35
|
return if @basic_statistics_calculated
|
36
36
|
@basic_statistics_calculated = true
|
37
|
-
|
37
|
+
|
38
38
|
@lines_count = code.blank? ? 0 : 1
|
39
39
|
@characters_count = 0
|
40
40
|
code.chars do |c|
|
@@ -43,92 +43,92 @@ module CodeStats::Languages
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
module CComments
|
48
48
|
def code
|
49
|
-
@code ||= text.substitute(/\/\*.+?\*\/\n?/m, '').substitute(/^\/\/.+?[\n\z]/m, '')
|
49
|
+
@code ||= text.substitute(/\/\*.+?\*\/\n?/m, '').substitute(/^\/\/.+?[\n\z]/m, '').substitute(/\/\/.+?$/, '')
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
module SharpComments
|
54
54
|
def code
|
55
|
-
@code ||= text.substitute(/^#.+?[\n\z]/m, '')
|
55
|
+
@code ||= text.substitute(/^#.+?[\n\z]/m, '').substitute(/#.+?$/, '')
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
class Java < Abstract
|
60
60
|
include CComments
|
61
|
-
|
62
|
-
extensions :java
|
61
|
+
|
62
|
+
extensions :java
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
class JavaScript < Abstract
|
66
66
|
include CComments
|
67
|
-
|
67
|
+
|
68
68
|
extensions :js
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
class Ruby < Abstract
|
72
72
|
include SharpComments
|
73
|
-
|
73
|
+
|
74
74
|
extensions :rb
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
class Cpp < Abstract
|
78
78
|
include CComments
|
79
|
-
|
79
|
+
|
80
80
|
extensions :c, :cpp, :h
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
class Yaml < Abstract
|
84
84
|
include SharpComments
|
85
|
-
|
85
|
+
|
86
86
|
extensions :yml
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
class CoffeeScript < Abstract
|
90
90
|
include SharpComments
|
91
|
-
|
91
|
+
|
92
92
|
extensions :coffee
|
93
|
-
|
93
|
+
|
94
94
|
def code
|
95
|
-
@code ||= text.substitute(/###.+?###\n?/m, '').substitute(/^#.+?[\n\z]/m, '')
|
95
|
+
@code ||= text.substitute(/###.+?###\n?/m, '').substitute(/^#.+?[\n\z]/m, '').substitute(/#.+?$/, '')
|
96
96
|
end
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
class Haml < Abstract
|
100
100
|
extensions :haml
|
101
|
-
|
101
|
+
|
102
102
|
def code
|
103
|
-
@code ||= text.substitute(/^\/.+?[\n\z]/m, '')
|
103
|
+
@code ||= text.substitute(/^\/.+?[\n\z]/m, '').substitute(/^\s*\/.+?$/, '')
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
class Erb < Abstract
|
108
108
|
extensions :erb
|
109
|
-
|
109
|
+
|
110
110
|
def code
|
111
111
|
@code ||= text
|
112
112
|
end
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
class Rjs < Abstract
|
116
116
|
extensions :rjs
|
117
|
-
|
117
|
+
|
118
118
|
def code
|
119
119
|
@code ||= text
|
120
120
|
end
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
class Php < Abstract
|
124
124
|
include CComments
|
125
|
-
|
126
|
-
extensions :php
|
125
|
+
|
126
|
+
extensions :php
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
class Python < Abstract
|
130
130
|
include SharpComments
|
131
|
-
|
131
|
+
|
132
132
|
extensions :py
|
133
133
|
end
|
134
134
|
end
|
data/lib/code_stats/project.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
class CodeStats::Project
|
2
|
-
attr_reader :path, :name, :
|
2
|
+
attr_reader :path, :name, :spec_filter, :skip_filter, :unknown_extensions
|
3
3
|
attr_reader :sources, :specs
|
4
|
-
|
5
|
-
AVAILIABLE_OPTIONS = [:
|
4
|
+
|
5
|
+
AVAILIABLE_OPTIONS = [:spec_filter, :skip_filter]
|
6
6
|
DEFAUL_SPEC_FILTER = /\/tests?\/|\/specs?\//
|
7
|
-
DEFAUL_SKIP_FILTER = /\/docs?\/|\/(s|ex)amples?\/|\/guides?\/|\/.git\/|\/tmp\/|database\.php/
|
8
|
-
|
7
|
+
DEFAUL_SKIP_FILTER = /\/docs?\/|\/(s|ex)amples?\/|\/guides?\/|\/.git\/|\/tmp\/|\/old\/|database\.php/
|
8
|
+
|
9
9
|
def initialize path, options = {}
|
10
|
-
@path, @name = path, path.to_entry.name
|
10
|
+
@path, @name = path, path.to_entry.name
|
11
11
|
options.validate_options! *AVAILIABLE_OPTIONS
|
12
|
-
@
|
12
|
+
@spec_filter = options.include?(:spec_filter) ? options[:spec_filter] : DEFAUL_SPEC_FILTER
|
13
13
|
@skip_filter = options.include?(:skip_filter) ? options[:skip_filter] : DEFAUL_SKIP_FILTER
|
14
14
|
clear
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def files &b
|
18
18
|
files = []
|
19
19
|
path.to_dir.files '**/*.*' do |file|
|
@@ -22,33 +22,33 @@ class CodeStats::Project
|
|
22
22
|
end
|
23
23
|
b ? nil : files
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
delegate :lines_count, :characters_count, :lines_count_by_language, :characters_count_by_language, to: :sources
|
27
|
-
|
27
|
+
|
28
28
|
def analyze!
|
29
|
-
clear
|
30
|
-
files do |file|
|
29
|
+
clear
|
30
|
+
files do |file|
|
31
31
|
ext = file.extension.to_sym
|
32
32
|
if CodeStats.know?(ext)
|
33
33
|
warn("file #{file} is too big, skipping") and next if file.size > CodeStats.file_size_limit
|
34
|
-
script = CodeStats.parse file.read.force_utf8_encoding, ext
|
34
|
+
script = CodeStats.parse file.read.force_utf8_encoding, ext
|
35
35
|
source?(file) ? sources.add(script) : specs.add(script)
|
36
36
|
else
|
37
37
|
unknown_extensions << ext unless unknown_extensions.include? ext
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
protected
|
43
43
|
def clear
|
44
44
|
@unknown_extensions = []
|
45
45
|
@sources, @specs = CodeStats::FileSet.new, CodeStats::FileSet.new
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def source? file
|
49
|
-
!(
|
49
|
+
!(spec_filter && (file.path.sub(path, '') =~ spec_filter))
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def skip? file
|
53
53
|
skip_filter && (file.path.sub(path, '') =~ skip_filter)
|
54
54
|
end
|
data/lib/code_stats/report.rb
CHANGED
@@ -2,9 +2,9 @@ class CodeStats::Report
|
|
2
2
|
attr_reader :filters, :projects
|
3
3
|
def initialize *args
|
4
4
|
@filters = args.extract_options!
|
5
|
-
@projects = args
|
5
|
+
@projects = args
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def render
|
9
9
|
# preparing data
|
10
10
|
data = projects.clone
|
@@ -12,30 +12,30 @@ class CodeStats::Report
|
|
12
12
|
data.collect! do |p|
|
13
13
|
o = OpenObject.new
|
14
14
|
o.name = p.name
|
15
|
-
|
15
|
+
|
16
16
|
o.characters_count = p.characters_count(filters)
|
17
|
-
o.characters_count_by_language = p.characters_count_by_language(filters)
|
17
|
+
o.characters_count_by_language = p.characters_count_by_language(filters)
|
18
18
|
o.ignored_characters_count_by_language = p.characters_count_by_language.reject do |lang, count|
|
19
19
|
o.characters_count_by_language.include?(lang)
|
20
20
|
end
|
21
|
-
|
22
|
-
o.specs = OpenObject.new
|
21
|
+
|
22
|
+
o.specs = OpenObject.new
|
23
23
|
o.specs.characters_count = p.specs.characters_count(filters)
|
24
|
-
o.specs.characters_count_by_language = p.specs.characters_count_by_language(filters)
|
24
|
+
o.specs.characters_count_by_language = p.specs.characters_count_by_language(filters)
|
25
25
|
o.specs.ignored_characters_count_by_language = p.specs.characters_count_by_language.reject do |lang, count|
|
26
26
|
o.specs.characters_count_by_language.include?(lang)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
o.unknown_extensions = p.unknown_extensions
|
30
|
-
|
30
|
+
|
31
31
|
o
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# rendering
|
35
35
|
dir = __FILE__.dirname.to_dir
|
36
36
|
css = [dir['report/style.css'].read].join("\n")
|
37
37
|
js = %w(jquery.js highchart.js report.js).collect{|n| dir["report/#{n}"].read}.join("\n")
|
38
|
-
|
38
|
+
|
39
39
|
report = dir / 'report.html.haml'
|
40
40
|
report.render(projects: data, filters: filters, css: css, js: js)
|
41
41
|
end
|
data/lib/code_stats/support.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
String.class_eval do
|
2
|
-
# Ruby just crashes on some files, don't know why and don't want to
|
2
|
+
# Ruby just crashes on some files, don't know why and don't want to
|
3
3
|
# spend time on this shit, just found this hack somewhere in the internet.
|
4
4
|
def force_utf8_encoding
|
5
5
|
force_encoding('binary').gsub(156.chr,"Oe")
|
data/readme.md
CHANGED
@@ -8,17 +8,17 @@ Screenshots showing us: Complexity of [Rails libraries][rails-img], comparison o
|
|
8
8
|
|
9
9
|
# Installation & Usage
|
10
10
|
|
11
|
-
|
11
|
+
The tool is language-agnostic, but to use it You need Ruby installed, to install type:
|
12
12
|
|
13
13
|
``` bash
|
14
14
|
gem install code_stats2
|
15
15
|
```
|
16
16
|
|
17
|
-
Now run it on some of Your projects, You can also specify some options (type '
|
17
|
+
Now run it on some of Your projects, You can also specify some options (type 'code_stats' without arguments to see full help):
|
18
18
|
|
19
19
|
``` bash
|
20
20
|
code_stats /projects/wordpress
|
21
|
-
code_stats /projects/* except
|
21
|
+
code_stats /projects/* --except JavaScript
|
22
22
|
```
|
23
23
|
|
24
24
|
Also You can easily customize it, sources are small and simple as an egg.
|
data/spec/code_stats_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Project" do
|
|
6
6
|
report = CodeStats::Report.new(*projects).render
|
7
7
|
report.should =~ /sample_project.+32/m
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should also accept options (from error)" do
|
11
11
|
projects = CodeStats.analyze sample_project_path
|
12
12
|
report = CodeStats::Report.new(*(projects << {except: :JavaScript})).render
|
data/spec/languages_spec.rb
CHANGED
@@ -5,7 +5,7 @@ shared_examples_for 'language' do
|
|
5
5
|
lang = CodeStats.parse @script, @extension
|
6
6
|
lang.code.should == <<-CODE
|
7
7
|
code_a
|
8
|
-
code_b
|
8
|
+
code_b
|
9
9
|
CODE
|
10
10
|
# lang.code.should_not include 'comment_a'
|
11
11
|
# lang.code.should_not include 'comment_a2'
|
@@ -16,7 +16,7 @@ end
|
|
16
16
|
|
17
17
|
describe "Java" do
|
18
18
|
it_should_behave_like "language"
|
19
|
-
|
19
|
+
|
20
20
|
before do
|
21
21
|
@extension = :java
|
22
22
|
@script = <<-JAVA
|
@@ -29,14 +29,14 @@ comment_a
|
|
29
29
|
*/
|
30
30
|
// comment_b
|
31
31
|
// comment_b2
|
32
|
-
code_b
|
32
|
+
code_b // comment_b3
|
33
33
|
JAVA
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "JavaScript" do
|
38
38
|
it_should_behave_like "language"
|
39
|
-
|
39
|
+
|
40
40
|
before do
|
41
41
|
@extension = :js
|
42
42
|
@script = <<-JAVA_SCRIPT
|
@@ -49,10 +49,10 @@ comment_a
|
|
49
49
|
*/
|
50
50
|
// comment_b
|
51
51
|
// comment_b2
|
52
|
-
code_b
|
52
|
+
code_b // comment_b3
|
53
53
|
JAVA_SCRIPT
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "removing comments should correctly change lines count" do
|
57
57
|
script = <<-JAVA_SCRIPT
|
58
58
|
// a variable
|
@@ -74,7 +74,7 @@ b = 2;
|
|
74
74
|
|
75
75
|
alert(a + b);
|
76
76
|
JAVA_SCRIPT
|
77
|
-
|
77
|
+
|
78
78
|
lang = CodeStats.parse script, :js
|
79
79
|
lang.code.should == code
|
80
80
|
end
|
@@ -82,21 +82,21 @@ end
|
|
82
82
|
|
83
83
|
describe "Ruby" do
|
84
84
|
it_should_behave_like "language"
|
85
|
-
|
85
|
+
|
86
86
|
before do
|
87
87
|
@extension = :rb
|
88
88
|
@script = <<-RUBY
|
89
89
|
code_a
|
90
90
|
# comment_a
|
91
91
|
# comment_a2
|
92
|
-
code_b
|
92
|
+
code_b # comment_b3
|
93
93
|
RUBY
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
describe "Cpp" do
|
98
98
|
it_should_behave_like "language"
|
99
|
-
|
99
|
+
|
100
100
|
before do
|
101
101
|
@extension = :cpp
|
102
102
|
@script = <<-CPP
|
@@ -109,14 +109,14 @@ comment_a
|
|
109
109
|
*/
|
110
110
|
// comment_b
|
111
111
|
// comment_b2
|
112
|
-
code_b
|
112
|
+
code_b // comment_b3
|
113
113
|
CPP
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
117
|
describe "CoffeeScript" do
|
118
118
|
it_should_behave_like "language"
|
119
|
-
|
119
|
+
|
120
120
|
before do
|
121
121
|
@extension = :coffee
|
122
122
|
@script = <<-COFFEE_SCRIPT
|
@@ -129,66 +129,66 @@ comment_a2
|
|
129
129
|
###
|
130
130
|
# comment_b
|
131
131
|
# comment_b2
|
132
|
-
code_b
|
132
|
+
code_b # comment_b3
|
133
133
|
COFFEE_SCRIPT
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
137
|
describe "Yaml" do
|
138
138
|
it_should_behave_like "language"
|
139
|
-
|
139
|
+
|
140
140
|
before do
|
141
141
|
@extension = :yml
|
142
142
|
@script = <<-YAML
|
143
143
|
code_a
|
144
144
|
# comment_a
|
145
145
|
# comment_a2
|
146
|
-
code_b
|
146
|
+
code_b # comment_b3
|
147
147
|
YAML
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
151
|
describe "Haml" do
|
152
152
|
it_should_behave_like "language"
|
153
|
-
|
153
|
+
|
154
154
|
before do
|
155
155
|
@extension = :haml
|
156
156
|
@script = <<-HAML
|
157
157
|
code_a
|
158
158
|
/ comment_a
|
159
159
|
/ comment_a2
|
160
|
-
code_b
|
160
|
+
code_b
|
161
161
|
HAML
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
165
|
describe "Erb" do
|
166
166
|
it_should_behave_like "language"
|
167
|
-
|
167
|
+
|
168
168
|
before do
|
169
169
|
@extension = :erb
|
170
170
|
@script = <<-ERB
|
171
171
|
code_a
|
172
|
-
code_b
|
172
|
+
code_b
|
173
173
|
ERB
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
177
|
describe "Rjs" do
|
178
178
|
it_should_behave_like "language"
|
179
|
-
|
179
|
+
|
180
180
|
before do
|
181
181
|
@extension = :rjs
|
182
182
|
@script = <<-RJS
|
183
183
|
code_a
|
184
|
-
code_b
|
184
|
+
code_b
|
185
185
|
RJS
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
189
|
describe "Php" do
|
190
190
|
it_should_behave_like "language"
|
191
|
-
|
191
|
+
|
192
192
|
before do
|
193
193
|
@extension = :php
|
194
194
|
@script = <<-PHP
|
@@ -201,21 +201,21 @@ comment_a
|
|
201
201
|
*/
|
202
202
|
// comment_b
|
203
203
|
// comment_b2
|
204
|
-
code_b
|
204
|
+
code_b // comment_b3
|
205
205
|
PHP
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
209
|
describe "Python" do
|
210
210
|
it_should_behave_like "language"
|
211
|
-
|
211
|
+
|
212
212
|
before do
|
213
213
|
@extension = :py
|
214
214
|
@script = <<-PYTHON
|
215
215
|
code_a
|
216
216
|
# comment_a
|
217
217
|
# comment_a2
|
218
|
-
code_b
|
218
|
+
code_b # comment_b3
|
219
219
|
PYTHON
|
220
220
|
end
|
221
221
|
end
|
data/spec/project_spec.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Project" do
|
3
|
+
describe "Project" do
|
4
4
|
it "general" do
|
5
5
|
prj = CodeStats::Project.new sample_project_path
|
6
6
|
prj.name.should == 'sample_project'
|
7
7
|
prj.files.size.should == 4
|
8
|
-
|
8
|
+
|
9
9
|
prj.analyze!
|
10
|
-
|
10
|
+
|
11
11
|
prj.unknown_extensions.should == [:unknown]
|
12
|
-
|
12
|
+
|
13
13
|
# sources
|
14
14
|
prj.lines_count.should == 10
|
15
15
|
prj.characters_count.should == 32
|
16
16
|
|
17
17
|
prj.lines_count_by_language.should == {JavaScript: 5, Ruby: 5}
|
18
18
|
prj.characters_count_by_language.should == {JavaScript: 19, Ruby: 13}
|
19
|
-
|
19
|
+
|
20
20
|
# specs
|
21
21
|
prj.specs.lines_count.should == 2
|
22
22
|
prj.specs.characters_count.should == 16
|
23
23
|
|
24
24
|
prj.specs.lines_count_by_language.should == {Ruby: 2}
|
25
|
-
prj.specs.characters_count_by_language.should == {Ruby: 16}
|
25
|
+
prj.specs.characters_count_by_language.should == {Ruby: 16}
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "language filters" do
|
29
29
|
prj = CodeStats::Project.new sample_project_path
|
30
30
|
prj.analyze!
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_stats2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-09-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby_ext
|
16
|
-
requirement: &
|
16
|
+
requirement: &2844590 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.4'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2844590
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: vfs
|
27
|
-
requirement: &
|
27
|
+
requirement: &2844350 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0.3'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2844350
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: haml
|
38
|
-
requirement: &
|
38
|
+
requirement: &2844110 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.1'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2844110
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: tilt
|
49
|
-
requirement: &
|
49
|
+
requirement: &2843870 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '1.3'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2843870
|
58
58
|
description:
|
59
59
|
email:
|
60
60
|
executables:
|