gloc 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/gloc +20 -5
- data/lib/gloc/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84cd3269290d4f6060a13a68ef4dcec9026f3fb
|
4
|
+
data.tar.gz: d43d54e3fc77fb43c86221c3489e5ad0c579d8e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7069c3b6398ffcf1646cc450777e75eb21dbb9a8e90e12a0629cc64daefecc47fe669d2f654050fd2503e2f6e0e886ee0fdb185bd0681326eec1b3f6ec8eef4e
|
7
|
+
data.tar.gz: ad03367f2daac51f628efd9a7b78407880d0556487c9e05e8499b08700399df983febf75cdb3aa5aa24196a21a424fe08a656872183caa9793cf85da07159847
|
data/exe/gloc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'ostruct'
|
4
4
|
|
5
|
-
source_files = if STDIN.tty?
|
5
|
+
source_files = if STDIN.tty? || $tty
|
6
6
|
`git rev-parse --show-toplevel &> /dev/null`
|
7
7
|
if $?.success?
|
8
8
|
# we're inside a git repo so
|
@@ -54,7 +54,7 @@ COMMENTS = {
|
|
54
54
|
'*.js' => %r{\A\s*(//.*|/\*.*\*/)\s*\Z},
|
55
55
|
}.freeze
|
56
56
|
|
57
|
-
source_stats =
|
57
|
+
source_stats = source_files.each_with_object({}) { |file, stats|
|
58
58
|
file_ext = '*' + File.extname(file) # e.g. '*.rb' or '*' if no ext!
|
59
59
|
stats_for_ext = begin
|
60
60
|
stats[file_ext] ||= OpenStruct.new({
|
@@ -69,7 +69,7 @@ source_stats = Hash[source_files.each_with_object({}) { |file, stats|
|
|
69
69
|
stats_for_ext.line_count += source_lines.count
|
70
70
|
stats_for_ext.blank_count += source_lines.grep(BLANKS).count
|
71
71
|
stats_for_ext.comment_count += source_lines.grep(COMMENTS[file_ext]).count
|
72
|
-
}
|
72
|
+
}
|
73
73
|
|
74
74
|
source_stats.values.each do |stats_for_ext|
|
75
75
|
stats_for_ext.code_count = stats_for_ext.line_count - (
|
@@ -77,6 +77,21 @@ source_stats.values.each do |stats_for_ext|
|
|
77
77
|
)
|
78
78
|
end
|
79
79
|
|
80
|
+
sort_metric = case
|
81
|
+
when $files then :file_count
|
82
|
+
when $lines then :line_count
|
83
|
+
when $blank then :blank_count
|
84
|
+
when $comment then :comment_count
|
85
|
+
when $code then :code_count
|
86
|
+
else :code_count
|
87
|
+
end
|
88
|
+
|
89
|
+
source_stats = Hash[
|
90
|
+
source_stats.sort_by { |_, stats|
|
91
|
+
stats.send(sort_metric)
|
92
|
+
}.reverse
|
93
|
+
]
|
94
|
+
|
80
95
|
source_stats["TOTAL"] = OpenStruct.new({
|
81
96
|
file_count: source_stats.values.map(&:file_count).reduce(:+),
|
82
97
|
line_count: source_stats.values.map(&:line_count).reduce(:+),
|
@@ -89,7 +104,7 @@ source_stats["TOTAL"] = OpenStruct.new({
|
|
89
104
|
# JSON formatting for non-TTY output
|
90
105
|
#
|
91
106
|
|
92
|
-
unless STDOUT.tty?
|
107
|
+
unless STDOUT.tty? || $tty
|
93
108
|
require 'json'
|
94
109
|
|
95
110
|
class OpenStruct
|
@@ -136,7 +151,7 @@ end
|
|
136
151
|
|
137
152
|
totals = source_stats.delete("TOTAL").to_h.values
|
138
153
|
|
139
|
-
TEMPLATE = " %-13s %12s %12s %12s %12s %12s
|
154
|
+
TEMPLATE = " %-13s %12s %12s %12s %12s %12s".freeze
|
140
155
|
DIVIDER = ('-' * 80).freeze # `loc` uses 80 columns
|
141
156
|
|
142
157
|
puts format("%s\n#{TEMPLATE}\n%s",
|
data/lib/gloc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gloc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Vandenberk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|