gitloc-matthewswan 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f03111984ba5bf6b5cc7021c25319be615d53993
4
- data.tar.gz: f58cccf412c93dead7ef99dd48120248fac73e28
3
+ metadata.gz: 055df75ec3be7abd221b94efd9964fab7cf21e51
4
+ data.tar.gz: 393ff28f6c5d3ad01b8a3289ae22db253246614d
5
5
  SHA512:
6
- metadata.gz: 918c4d4b835777bb53f64e5b0164f752790e591397a0aeb23d459567554fc66af1b9a2ed2927fe35178621480e154fa360c030f5b150864f2623b1aca1121a71
7
- data.tar.gz: 58cc4321c4fa9bb83a0af76e221f52b504226d1219815e2ba6c43f154d993392c3d696ff9b44043c8e6b9e2426ab4a34209da858c00080d03ea14370da556ceb
6
+ metadata.gz: ffbf4aacbb9288cf1063327960535e59edb74e8a3c73e59bf902a3573b1c818018c333acfcf4f0c3bcc9ffc77fe52085f0da754fb1ac41091dd5ace570c5b8e3
7
+ data.tar.gz: d6a87b96ad72daddaf6ddf9fc721d6ab98f2a954e3b6e2b314e294618c5790ad664033b71fd0fba28616c5d465ad476d0aee9d830646a6d17d07550a09514e93
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gitloc-matthewswan (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.4.0)
17
+ rspec-core (~> 3.4.0)
18
+ rspec-expectations (~> 3.4.0)
19
+ rspec-mocks (~> 3.4.0)
20
+ rspec-core (3.4.2)
21
+ rspec-support (~> 3.4.0)
22
+ rspec-expectations (3.4.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.4.0)
25
+ rspec-mocks (3.4.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.4.0)
28
+ rspec-support (3.4.1)
29
+ slop (3.6.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ gitloc-matthewswan!
36
+ pry
37
+ rspec (~> 3.0)
38
+
39
+ BUNDLED WITH
40
+ 1.11.2
data/bin/gitloc CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
- require 'gitloc'
5
- Gitloc.call(ARGV, $stdout, $stderr)
4
+ require 'gitloc/binary'
5
+ Gitloc::Binary.call(ARGV, $stdout, $stderr)
data/gitloc.gemspec CHANGED
@@ -10,7 +10,9 @@ Gem::Specification.new do |s|
10
10
  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."
11
11
  s.authors = ["Matthew Swan"]
12
12
  s.email = 'swanm86@gmail.com'
13
- s.files = Dir["**/*"].select { |f| File.file? f }
13
+ s.files = Dir["**/*"].select { |f| File.file? f } - Dir['*.gem']
14
14
  s.homepage = 'https://github.com/MatthewSwan/gitloc'
15
15
  s.executables << 'gitloc'
16
+ s.add_development_dependency 'rspec', '~> 3.0'
17
+ s.add_development_dependency 'pry'
16
18
  end
data/lib/gitloc.rb CHANGED
@@ -1,24 +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(argv, outstream, errstream)
8
- repo = argv.first
9
- Dir.mktmpdir { |dir|
9
+ def self.call(repo)
10
+ names_to_bodies = Dir.mktmpdir { |dir|
10
11
  Dir.chdir dir
11
12
  out, err, status = Open3.capture3 'git', 'clone', repo, 'cloned'
12
- unless status.success?
13
- errstream.puts out, err
14
- exit "Failed somehow >.<"
15
- end
13
+ raise RepoDoesNotExistError, repo unless status.success?
16
14
  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}"
21
- end
15
+ Dir['**/*'].reject { |name| File.directory? name }
16
+ .map { |name| [name, File.read(name) ] }
22
17
  }
18
+
19
+ LineCounts.call(names_to_bodies)
23
20
  end
24
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,9 @@
1
+ class Gitloc
2
+ Error = Class.new StandardError
3
+
4
+ class RepoDoesNotExistError < Error
5
+ def initialize(repo_name)
6
+ super "#{repo_name} does not exist"
7
+ end
8
+ end
9
+ 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
@@ -1,3 +1,3 @@
1
1
  class Gitloc
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,8 @@
1
+ require 'gitloc'
2
+
3
+ RSpec.describe Gitloc do
4
+ it 'raises RepoDoesNotExistError when the repo does not exist' do
5
+ expect { Gitloc.call("not-a-repo") }
6
+ .to raise_error Gitloc::RepoDoesNotExistError, /not-a-repo/
7
+ end
8
+ end
@@ -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,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitloc-matthewswan
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
  - Matthew Swan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-23 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-02-29 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'
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: swanm86@gmail.com
@@ -18,14 +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.gemspec
24
54
  - lib/gitloc.rb
55
+ - lib/gitloc/binary.rb
56
+ - lib/gitloc/errors.rb
57
+ - lib/gitloc/line_counts.rb
25
58
  - lib/gitloc/version.rb
26
- - seeing_is_believing-2.2.0.gem
27
59
  - spec/acceptance_spec.rb
28
60
  - spec/fixtures/2loc
61
+ - spec/gitloc_spec.rb
62
+ - spec/line_counts_spec.rb
29
63
  homepage: https://github.com/MatthewSwan/gitloc
30
64
  licenses:
31
65
  - MIT
Binary file