gitloc-joshcheek 0.1.1 → 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/Gemfile +2 -0
- data/Gemfile.lock +37 -0
- data/bin/gitloc +2 -2
- data/gitloc.gemspec +2 -1
- data/lib/gitloc.rb +9 -13
- data/lib/gitloc/binary.rb +13 -0
- data/lib/gitloc/errors.rb +9 -0
- data/lib/gitloc/line_counts.rb +15 -0
- data/lib/gitloc/version.rb +1 -1
- data/spec/gitloc_spec.rb +8 -0
- data/spec/line_counts_spec.rb +27 -0
- metadata +24 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ec9dcb4b36696c324cc09aec617329dff6c7655
|
4
|
+
data.tar.gz: bbc405ce8916d69c63932d041eceb2bae1f56b0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fbd3346232119866b67fec2d385f0762eb7d8b35f533c4adc2f70871a1a4efb3a2cc9218a0f4cc86e51647ad3e0408559356c487e8495871780d0a3a32aaecc
|
7
|
+
data.tar.gz: 46140da2cb32f341383e2fb7a8b1dc64dc70d9ad3b3e43e335a962a5104781509795e9271b0fd684e60d832156aa12d17867dd6d68997ce799e8b61a624ce584
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gitloc-joshcheek (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.0)
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
method_source (0.8.2)
|
12
|
+
pry (0.10.1)
|
13
|
+
coderay (~> 1.1.0)
|
14
|
+
method_source (~> 0.8.1)
|
15
|
+
slop (~> 3.4)
|
16
|
+
rspec (3.2.0)
|
17
|
+
rspec-core (~> 3.2.0)
|
18
|
+
rspec-expectations (~> 3.2.0)
|
19
|
+
rspec-mocks (~> 3.2.0)
|
20
|
+
rspec-core (3.2.0)
|
21
|
+
rspec-support (~> 3.2.0)
|
22
|
+
rspec-expectations (3.2.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.2.0)
|
25
|
+
rspec-mocks (3.2.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.2.0)
|
28
|
+
rspec-support (3.2.1)
|
29
|
+
slop (3.6.0)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
gitloc-joshcheek!
|
36
|
+
pry
|
37
|
+
rspec (~> 3.0)
|
data/bin/gitloc
CHANGED
data/gitloc.gemspec
CHANGED
@@ -9,7 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.description = "Example project for the Turing School of Software and Design, see https://github.com/JoshCheek/elective-building-a-gem -- gives lines-of-code information for a git repo."
|
10
10
|
s.authors = ["Josh Cheek"]
|
11
11
|
s.email = 'josh.cheek@gmail.com'
|
12
|
-
s.files = Dir["**/*"].select { |f| File.file? f }
|
12
|
+
s.files = Dir["**/*"].select { |f| File.file? f } - Dir['*.gem']
|
13
13
|
s.homepage = 'https://github.com/JoshCheek/elective-building-a-gem'
|
14
14
|
s.executables << 'gitloc'
|
15
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
15
16
|
end
|
data/lib/gitloc.rb
CHANGED
@@ -1,25 +1,21 @@
|
|
1
1
|
require 'tmpdir'
|
2
2
|
require 'open3'
|
3
3
|
|
4
|
+
require 'gitloc/errors'
|
4
5
|
require 'gitloc/version'
|
6
|
+
require 'gitloc/line_counts'
|
5
7
|
|
6
8
|
class Gitloc
|
7
|
-
def self.call(
|
8
|
-
|
9
|
-
|
10
|
-
Dir.mktmpdir { |dir|
|
9
|
+
def self.call(repo)
|
10
|
+
names_to_bodies = Dir.mktmpdir { |dir|
|
11
11
|
Dir.chdir dir
|
12
12
|
out, err, status = Open3.capture3 'git', 'clone', repo, 'cloned'
|
13
|
-
unless status.success?
|
14
|
-
errstream.puts out, err
|
15
|
-
exit "Failed somehow >.<"
|
16
|
-
end
|
13
|
+
raise RepoDoesNotExistError, repo unless status.success?
|
17
14
|
Dir.chdir 'cloned'
|
18
|
-
|
19
|
-
|
20
|
-
loc = File.readlines(filename).count { |line| line !~ /^\s*$/ }
|
21
|
-
outstream.puts "#{loc}\t#{filename}"
|
22
|
-
end
|
15
|
+
Dir['**/*'].reject { |name| File.directory? name }
|
16
|
+
.map { |name| [name, File.read(name) ] }
|
23
17
|
}
|
18
|
+
|
19
|
+
LineCounts.call(names_to_bodies)
|
24
20
|
end
|
25
21
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'gitloc'
|
2
|
+
|
3
|
+
class Gitloc
|
4
|
+
class Binary
|
5
|
+
def self.call(argv, outstream, errstream)
|
6
|
+
repo = argv.first
|
7
|
+
files_to_lines = Gitloc.call(repo)
|
8
|
+
files_to_lines.each do |filename, loc|
|
9
|
+
outstream.puts "#{loc}\t#{filename}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Gitloc
|
2
|
+
module LineCounts
|
3
|
+
def self.call(names_to_bodies)
|
4
|
+
names_to_bodies
|
5
|
+
.map { |name, body| [name, count_lines(body)] }
|
6
|
+
.select { |name, body| body }
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.count_lines(body)
|
10
|
+
body.lines.count { |line| line !~ /^\s*$/ }
|
11
|
+
rescue ArgumentError
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/gitloc/version.rb
CHANGED
data/spec/gitloc_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'gitloc/line_counts'
|
2
|
+
|
3
|
+
RSpec.describe Gitloc::LineCounts do
|
4
|
+
it 'returns the counts for each file' do
|
5
|
+
counts = described_class.call([["file1", "l1"],
|
6
|
+
["file2", "l1\nl2\nl3"]])
|
7
|
+
expect(counts).to eq [["file1", 1], ["file2", 3]]
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'does not count empty lines' do
|
11
|
+
counts = described_class.call([["file1", ""]])
|
12
|
+
expect(counts).to eq [["file1", 0]]
|
13
|
+
|
14
|
+
counts = described_class.call([["file1", "\n"]])
|
15
|
+
expect(counts).to eq [["file1", 0]]
|
16
|
+
|
17
|
+
counts = described_class.call([["file1", "\nline1\nline2\n"]])
|
18
|
+
expect(counts).to eq [["file1", 2]]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'omits files of binary data' do
|
22
|
+
counts = described_class.call([["keep1", ""],
|
23
|
+
["binary", "GIF89a\u0000\u0002\u0000\u0001\xD5\u0000\u0000\xCD\xCF\xCF\u00135A/IR\x89\x91\u0017\x85\x92\x93rx{\xBA\xBC\xBD\n"],
|
24
|
+
["keep2", ""]])
|
25
|
+
expect(counts).to eq [["keep1", 0], ["keep2", 0]]
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitloc-joshcheek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Cheek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
12
|
-
dependencies:
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
13
27
|
description: Example project for the Turing School of Software and Design, see https://github.com/JoshCheek/elective-building-a-gem
|
14
28
|
-- gives lines-of-code information for a git repo.
|
15
29
|
email: josh.cheek@gmail.com
|
@@ -18,13 +32,20 @@ executables:
|
|
18
32
|
extensions: []
|
19
33
|
extra_rdoc_files: []
|
20
34
|
files:
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
21
37
|
- Readme.md
|
22
38
|
- bin/gitloc
|
23
39
|
- gitloc.gemspec
|
24
40
|
- lib/gitloc.rb
|
41
|
+
- lib/gitloc/binary.rb
|
42
|
+
- lib/gitloc/errors.rb
|
43
|
+
- lib/gitloc/line_counts.rb
|
25
44
|
- lib/gitloc/version.rb
|
26
45
|
- spec/acceptance_spec.rb
|
27
46
|
- spec/fixtures/2loc
|
47
|
+
- spec/gitloc_spec.rb
|
48
|
+
- spec/line_counts_spec.rb
|
28
49
|
homepage: https://github.com/JoshCheek/elective-building-a-gem
|
29
50
|
licenses:
|
30
51
|
- MIT
|