gitloc-marissa 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9581a63ce3be83e4e4655e43c15aef45b9bbe9cc58b2efd4b31d48c383e91a8b
4
- data.tar.gz: 1377b5a374c082b687dcbe7ee491fec0ab46ee10ad6c6598085f2bda2641ab96
3
+ metadata.gz: 1ab9ef37c6d4d357c645035cea12eff17c21a46d200ce254f209775ad794cb89
4
+ data.tar.gz: b594f3914dc4b6497b61c3b634422b72842002d5d47ba59a9a5d611bd5e54730
5
5
  SHA512:
6
- metadata.gz: fdc9c010737cf5f365dd13a97b8223cd924006eb2db76e75e9e37edef3479b7b1fe259cd749a61b77093a8e8a9afd632a3160d91bd2aea8bffd4269a9c25f832
7
- data.tar.gz: '04788c9756b9662debe56856347fb2ea1c707f703c90925357c189bfcd47d44b76af68ca1a688450bd4aac91a9d02d45771753d837689bfc9f4cbee12e52b96c'
6
+ metadata.gz: d45da33a4946d516a0d7e140257ee95bfdff28845a624c61fa8059253cf2727e28f392f73164a6140c7c5a210fb56ee49c3b432686fb960d8a5f27337dc17560
7
+ data.tar.gz: 1a1c577144851179fa93b0346f9f0d7e22df3798f71e8f27fee48aa39531e7f3a1b5d5d1187c40822b80b040384f5721be7b0b7f9d909511af8ebeb5f5104b14
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gitloc-marissa (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.3)
10
+ diff-lcs (1.4.4)
11
+ method_source (1.0.0)
12
+ pry (0.13.1)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rspec (3.10.0)
16
+ rspec-core (~> 3.10.0)
17
+ rspec-expectations (~> 3.10.0)
18
+ rspec-mocks (~> 3.10.0)
19
+ rspec-core (3.10.0)
20
+ rspec-support (~> 3.10.0)
21
+ rspec-expectations (3.10.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-mocks (3.10.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-support (3.10.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ gitloc-marissa!
34
+ pry
35
+ rspec (~> 3.0)
36
+
37
+ BUNDLED WITH
38
+ 2.1.4
data/bin/gitloc CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
- require 'gitloc_marissa'
4
- GitlocMarissa.call(ARGV, $stdout, $stderr)
3
+ require 'gitloc_marissa/binary'
4
+ GitlocMarissa::Binary.call(ARGV, $stdout, $stderr)
@@ -12,4 +12,6 @@ Gem::Specification.new do |s|
12
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'
16
+ s.add_development_dependency 'pry'
15
17
  end
@@ -1,24 +1,26 @@
1
1
  require 'tmpdir'
2
2
  require 'open3'
3
3
  require 'gitloc_marissa/version'
4
+ require 'gitloc_marissa/errors'
5
+ require 'gitloc_marissa/line_counts'
4
6
 
5
7
  class GitlocMarissa
6
- def self.call(argv, outstream, errstream)
7
- repo = argv.first
8
+ def self.call(repo)
9
+ files_and_bodies = Dir.mktmpdir do |dir|
10
+ Dir.chdir dir do
11
+ out, err, status = Open3.capture3 'git', 'clone', repo, 'cloned'
8
12
 
9
- Dir.mktmpdir { |dir|
10
- Dir.chdir dir
11
- out, err, status = Open3.capture3 'git', 'clone', repo, 'cloned'
12
- unless status.success?
13
- errstream.puts out, err
14
- exit "Failed somehow >.<"
15
- end
16
- Dir.chdir 'cloned'
17
- files = Dir['**/*'].reject { |name| File.directory? name }
18
- files.each do |filename|
19
- loc = File.readlines(filename).count { |line| line !~ /^\s*$/ }
20
- outstream.puts "#{loc}\t#{filename}"
13
+ raise RepoDoesNotExistError, repo unless status.success?
14
+
15
+ Dir.chdir 'cloned' do
16
+ files = Dir['**/*'].reject { |name| File.directory? name }
17
+ files.map do |file|
18
+ body = File.read(file)
19
+ [file, body]
20
+ end
21
+ end
21
22
  end
22
- }
23
+ end
24
+ LineCounts.call(files_and_bodies)
23
25
  end
24
26
  end
@@ -0,0 +1,13 @@
1
+ require 'gitloc_marissa'
2
+
3
+ class GitlocMarissa
4
+ class Binary
5
+ def self.call(argv, outstream, errstream)
6
+ repo = argv.first
7
+ files_and_counts = GitlocMarissa.call(repo)
8
+ files_and_counts.each do |filename, loc|
9
+ outstream.puts "#{loc}\t#{filename}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ class GitlocMarissa
2
+ Error = Class.new StandardError
3
+ RepoDoesNotExistError = Class.new Error
4
+ end
@@ -0,0 +1,12 @@
1
+ class GitlocMarissa
2
+ module LineCounts
3
+ def self.call(files_and_bodies)
4
+ files_and_counts = files_and_bodies.map do |file, body|
5
+ count = body.lines.count { |line| line !~ /^\s*$/ }
6
+ [file, count]
7
+ rescue ArgumentError
8
+ end
9
+ files_and_counts.compact
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  class GitlocMarissa
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,8 @@
1
+ require 'gitloc_marissa'
2
+
3
+ RSpec.describe GitlocMarissa do
4
+ it 'raises RepoDoesNotExistError when the repo does not exist' do
5
+ expect { GitlocMarissa.call("not-a-repo") }
6
+ .to raise_error GitlocMarissa::RepoDoesNotExistError, /not-a-repo/
7
+ end
8
+ end
@@ -0,0 +1,27 @@
1
+ require 'gitloc_marissa/line_counts'
2
+
3
+ RSpec.describe GitlocMarissa::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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitloc-marissa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marissa Biesecker
@@ -9,7 +9,35 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-11-17 00:00:00.000000000 Z
12
- dependencies: []
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  description: Example project for the Turing School of Software and Design, see https://github.com/JoshCheek/elective-building-a-gem
14
42
  -- gives lines-of-code information for a git repo.
15
43
  email: marissa.biesecker@gmail.com
@@ -18,13 +46,20 @@ executables:
18
46
  extensions: []
19
47
  extra_rdoc_files: []
20
48
  files:
49
+ - Gemfile
50
+ - Gemfile.lock
21
51
  - README.md
22
52
  - bin/gitloc
23
53
  - gitloc-marissa.gemspec
24
54
  - lib/gitloc_marissa.rb
55
+ - lib/gitloc_marissa/binary.rb
56
+ - lib/gitloc_marissa/errors.rb
57
+ - lib/gitloc_marissa/line_counts.rb
25
58
  - lib/gitloc_marissa/version.rb
26
59
  - spec/acceptance_spec.rb
27
60
  - spec/fixtures/2loc
61
+ - spec/gitloc_marissa_spec.rb
62
+ - spec/line_counts_spec.rb
28
63
  homepage: https://github.com/JoshCheek/elective-building-a-gem
29
64
  licenses:
30
65
  - MIT