sloc 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -0
- data/README.md +5 -0
- data/Rakefile +9 -1
- data/bin/console +4 -8
- data/bin/setup +0 -0
- data/circle.yml +9 -0
- data/lib/sloc.rb +3 -5
- data/lib/sloc/analyzer.rb +33 -5
- data/lib/sloc/cli.rb +5 -4
- data/lib/sloc/runner.rb +44 -11
- data/lib/sloc/version.rb +1 -1
- data/sloc.gemspec +15 -12
- metadata +50 -7
- data/.travis.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e259712548f8143e04fdc705826079d117c2bca8
|
4
|
+
data.tar.gz: 04a88b96d2cee31d9e4e3973efbd97c759f35f40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ca49dea0ba4c645f0760cb1f2955825bb5fc1e03228346bc9a5fe8b8d7a11f5bc7ec5d29f64f2d62e9d5629bfa62c65491da5c967a6a67782f5e40f4192926c
|
7
|
+
data.tar.gz: 98f377612932aab8f82fd8b0bbefa781bf42efbe990ac20bfdf4a30c5b324928f63b9c433e0457832a42827c8013611ecb4b9dda6d12365be0c1cd420f355459
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
# Sloc
|
2
|
+
[](http://badge.fury.io/rb/sloc)
|
3
|
+
[](https://circleci.com/gh/meganemura/sloc)
|
4
|
+
[](https://coveralls.io/r/meganemura/sloc)
|
5
|
+
[](https://codeclimate.com/github/meganemura/sloc)
|
6
|
+
[](https://gemnasium.com/meganemura/sloc)
|
2
7
|
|
3
8
|
## Usage
|
4
9
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'sloc'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
9
|
+
require 'pry'
|
10
|
+
Pry.start
|
data/bin/setup
CHANGED
File without changes
|
data/circle.yml
ADDED
data/lib/sloc.rb
CHANGED
data/lib/sloc/analyzer.rb
CHANGED
@@ -1,19 +1,47 @@
|
|
1
1
|
module Sloc
|
2
2
|
class Analyzer
|
3
|
-
def initialize(options)
|
3
|
+
def initialize(options = {})
|
4
4
|
@options = options
|
5
5
|
end
|
6
6
|
|
7
|
+
REPORT_KEYS = [:total, :empty_lines, :single_comment]
|
8
|
+
|
7
9
|
def analyze(code, extension)
|
8
10
|
result = {}
|
9
11
|
|
10
|
-
code.gsub!(/\r\n|\r/, "\n")
|
12
|
+
code.scrub!.gsub!(/\r\n|\r/, "\n")
|
13
|
+
|
14
|
+
result[:total] = code.scan("\n").size
|
15
|
+
result[:empty_lines] = code.scan(/^\s*$/).size
|
11
16
|
|
12
|
-
|
13
|
-
result[:
|
14
|
-
result[:comments] = 'N/A' # FIXME
|
17
|
+
regexp = single_comment_expression(extension)
|
18
|
+
result[:single_comment] = regexp ? code.scan(regexp).size : 0
|
15
19
|
|
16
20
|
result
|
17
21
|
end
|
22
|
+
|
23
|
+
def comment_expressions(extension)
|
24
|
+
start, stop = block_comment_expression(extension)
|
25
|
+
|
26
|
+
{
|
27
|
+
single: single_comment_expression(extension),
|
28
|
+
start: start,
|
29
|
+
stop: stop,
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def single_comment_expression(extension)
|
34
|
+
case extension
|
35
|
+
when '.rb' then /#/
|
36
|
+
when '.vim' then /"/
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def block_comment_expression(extension)
|
41
|
+
case extension
|
42
|
+
when '.rb' then [/=begin/, /=end/]
|
43
|
+
else [nil, nil]
|
44
|
+
end
|
45
|
+
end
|
18
46
|
end
|
19
47
|
end
|
data/lib/sloc/cli.rb
CHANGED
@@ -10,9 +10,7 @@ module Sloc
|
|
10
10
|
def run(args = ARGV)
|
11
11
|
@options, paths = parse_options(args)
|
12
12
|
|
13
|
-
if paths.empty?
|
14
|
-
return help
|
15
|
-
end
|
13
|
+
return help if paths.empty? || @options[:help]
|
16
14
|
|
17
15
|
runner = Runner.new(@options)
|
18
16
|
|
@@ -20,8 +18,11 @@ module Sloc
|
|
20
18
|
end
|
21
19
|
|
22
20
|
def parse_options(args)
|
23
|
-
opts = Slop.parse! do |o|
|
21
|
+
opts = Slop.parse!(args) do |o|
|
24
22
|
o.on('-h', '--help', 'Display this help message.')
|
23
|
+
o.on('-o', '--order=', 'Specify key to order by.')
|
24
|
+
o.on('--desc', 'Reverse order if specified')
|
25
|
+
o.on('-l', '--limit=', 'Specify key to set limitation of displaying file number.')
|
25
26
|
end
|
26
27
|
|
27
28
|
[opts, args]
|
data/lib/sloc/runner.rb
CHANGED
@@ -2,41 +2,74 @@ require 'sloc/analyzer'
|
|
2
2
|
|
3
3
|
module Sloc
|
4
4
|
class Runner
|
5
|
-
def initialize(options)
|
5
|
+
def initialize(options = {})
|
6
6
|
@options = options
|
7
|
+
@analyzer = Analyzer.new(@options)
|
7
8
|
end
|
8
9
|
|
9
10
|
def run(paths)
|
11
|
+
# TODO: formatted output
|
12
|
+
require 'pp'
|
13
|
+
pp report(paths)
|
14
|
+
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def report(paths)
|
10
19
|
target_files = find_target_files(paths)
|
11
20
|
|
12
21
|
# TODO: count sloc
|
13
|
-
analyzer = Analyzer.new(@options)
|
14
22
|
report = target_files.each_with_object({}) do |path, h|
|
15
23
|
code = File.read(path)
|
16
24
|
extension = File.extname(path)
|
17
25
|
|
18
|
-
h[path] = analyzer.analyze(code, extension)
|
26
|
+
h[path] = @analyzer.analyze(code, extension)
|
19
27
|
end
|
20
28
|
|
21
|
-
|
22
|
-
require 'pp'
|
23
|
-
pp report
|
24
|
-
|
25
|
-
nil
|
29
|
+
process_options(report)
|
26
30
|
end
|
27
31
|
|
28
32
|
private
|
29
33
|
|
34
|
+
def process_options(report)
|
35
|
+
r = report
|
36
|
+
.sort_by { |_key, value| value[order] } # --order=
|
37
|
+
.tap { |hash| hash.reverse! if desc? } # --desc
|
38
|
+
|
39
|
+
if limit?
|
40
|
+
Hash[r.first(limitation)]
|
41
|
+
else
|
42
|
+
Hash[r]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def order
|
47
|
+
key = @options[:order] ? @options[:order].to_sym : nil
|
48
|
+
Analyzer::REPORT_KEYS.include?(key) ? key : Analyzer::REPORT_KEYS.first
|
49
|
+
end
|
50
|
+
|
51
|
+
def desc?
|
52
|
+
@options[:desc]
|
53
|
+
end
|
54
|
+
|
55
|
+
def limit?
|
56
|
+
!limitation.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
def limitation
|
60
|
+
@options[:limit] ? [@options[:limit].to_i, 0].max : nil
|
61
|
+
end
|
62
|
+
|
30
63
|
def find_target_files(paths)
|
31
64
|
files = paths.uniq.flat_map do |path|
|
32
65
|
if File.directory?(path)
|
33
|
-
Dir.glob("#{path}/**/*").select {|f| File.file?(f) }
|
66
|
+
Dir.glob("#{path}/**/*").select { |f| File.file?(f) }
|
34
67
|
else
|
35
|
-
path
|
68
|
+
File.exist?(path) ? path : nil
|
36
69
|
end
|
37
70
|
end
|
38
71
|
|
39
|
-
files.map {|f| File.expand_path(f) }.uniq
|
72
|
+
files.compact.map { |f| File.expand_path(f) }.uniq
|
40
73
|
end
|
41
74
|
end
|
42
75
|
end
|
data/lib/sloc/version.rb
CHANGED
data/sloc.gemspec
CHANGED
@@ -4,24 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'sloc/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'sloc'
|
8
8
|
spec.version = Sloc::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['meganemura']
|
10
|
+
spec.email = ['meganemura@users.noreply.github.com']
|
11
11
|
|
12
|
-
spec.summary =
|
12
|
+
spec.summary = 'A tool for counting source lines of code'
|
13
13
|
spec.description = spec.summary
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
14
|
+
spec.homepage = 'https://github.com/meganemura/sloc'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = 'exe'
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_dependency
|
22
|
+
spec.add_dependency 'slop', '~> 3.0'
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '>= 1.7'
|
25
|
+
spec.add_development_dependency 'coveralls'
|
26
|
+
spec.add_development_dependency 'pry'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec'
|
29
|
+
spec.add_development_dependency 'rubocop'
|
27
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sloc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- meganemura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|
@@ -28,16 +28,30 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.7'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coveralls
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: pry
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,34 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
69
111
|
description: A tool for counting source lines of code
|
70
112
|
email:
|
71
113
|
- meganemura@users.noreply.github.com
|
@@ -76,13 +118,14 @@ extra_rdoc_files: []
|
|
76
118
|
files:
|
77
119
|
- ".gitignore"
|
78
120
|
- ".rspec"
|
79
|
-
- ".
|
121
|
+
- ".rubocop.yml"
|
80
122
|
- Gemfile
|
81
123
|
- LICENSE.txt
|
82
124
|
- README.md
|
83
125
|
- Rakefile
|
84
126
|
- bin/console
|
85
127
|
- bin/setup
|
128
|
+
- circle.yml
|
86
129
|
- exe/sloc
|
87
130
|
- lib/sloc.rb
|
88
131
|
- lib/sloc/analyzer.rb
|
data/.travis.yml
DELETED