ruby-appraiser 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -52,9 +52,9 @@ class RubyAppraiser
52
52
  # true if file has a ruby shebang
53
53
  begin
54
54
  return true if File.open(filepath) do |file|
55
- file.read(20).chomp =~ /\A#\!.+ruby/
55
+ file.readline(20).chomp =~ /\A#\!.+ruby/
56
56
  end
57
- rescue Errno::ENOENT
57
+ rescue EOFError # file was empty
58
58
  rescue ArgumentError # invalid byte sequence
59
59
  end
60
60
 
@@ -79,7 +79,8 @@ class RubyAppraiser
79
79
  @appraisal.add_adapter(adapter) or
80
80
  raise "Unknown adapter '#{adapter}'"
81
81
  end
82
- Dir::chdir((`git rev-parse --show-toplevel`).chomp)
82
+ git_base = Git.run('rev-parse', '--show-toplevel', &:read).chomp
83
+ Dir.chdir(git_base)
83
84
  end
84
85
 
85
86
  def options
@@ -1,33 +1,24 @@
1
1
  # encoding: utf-8
2
+ require 'open3'
2
3
 
3
4
  class RubyAppraiser
4
5
  module Git
5
6
  extend self
6
7
 
7
8
  def authored_lines(options = {})
8
- diff_command = ['git', 'diff']
9
+ diff_command = ['diff']
9
10
  if options[:range]
10
11
  diff_command << options[:range]
11
12
  else
12
13
  diff_command << (options[:staged] ? '--cached' : 'HEAD')
13
14
  end
14
15
 
15
- diff_io = IO.popen(diff_command << {err: [:child, :out]})
16
- diff_output = diff_io.read
17
-
18
- case diff_output
19
- when /^fatal: Not a git/i
20
- then raise 'ruby-appraiser only works in git repos.'
21
- when /^fatal: ambiguous argument 'HEAD'/i
22
- then raise 'this ruby-appraiser mode only works with previous ' +
23
- 'commits, and your repository doesn\t appear to have ' +
24
- 'any. Make some commits first, or try a different mode.'
25
- end
16
+ diff_out = run(*diff_command)
26
17
 
27
18
  current_path, current_line = nil, nil
28
19
  authored_lines = Hash.new { |hash, key| hash[key] = [] }
29
20
 
30
- diff_output.lines do |line|
21
+ diff_out.each_line do |line|
31
22
  case line
32
23
  when /^---/ then next
33
24
  when /^\+\+\+ (?:b\/)?(.*)/
@@ -47,5 +38,22 @@ class RubyAppraiser
47
38
  not RubyAppraiser::rubytype? filepath
48
39
  end
49
40
  end
41
+
42
+ def run(*git_command)
43
+ stdin, stdout, stderr = Open3.popen3('git', *git_command)
44
+ stdin.close
45
+
46
+ case stderr.read
47
+ when /^fatal: Not a git/i
48
+ then raise 'ruby-appraiser only works in git repos.'
49
+ when /^fatal: ambiguous argument 'HEAD'/i
50
+ then raise 'this ruby-appraiser mode only works with previous ' +
51
+ 'commits, and your repository doesn\'t appear to have ' +
52
+ 'any. Make some commits first, or try a different mode.'
53
+ end
54
+
55
+ return yield(stdout) if block_given?
56
+ stdout
57
+ end
50
58
  end
51
59
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class RubyAppraiser
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-appraiser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-07 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake